Want fresh tech tips in your inbox?

XPath with HTML in PHP One Liner

       

Here is a one liner for using XPATH with HTML in PHP

$doc = new DOMXPath(@DOMDocument::loadHTML(file_get_contents("https://www.reddit.com/r/PHP/")));

Now you can use XPATH to query the html..

foreach($doc->query("//a") as $el){
    echo $el->nodeValue . " " . $el->getAttribute("href") . "\n";
}
Tagged w/ #php #xpath #xml #html #one liner

Apps I've Built

PhotoLocationChanger
Easily change the location on your photos and videos
Click here for more info about the app
PhotoDateChanger
Easily change the dates and times on your photos and videos
Click here for more info about the app
VocabReminder
English dictionary with notifications so you won't forget what you're studying!
Click here for more info about the app
VocabQuiz
The app that quizzes and scores you on your vocabulary!
Click here for more info about the app