Posted By

FatFolderDesigner on 02/13/12


php DOM

Versions (?)

jQuery syle DOM navigation in PHP with phpQuery

 / Published in: PHP


Navigating the DOM in jQuery is incredibly simple and thats to phpQuery you can do the same in php. Below are some examples of how it's used, the key change bing that instead of $() you use pq(), and instead of a . you used ->. Theres alot more details information at the link if your interested. Post questions/comments here or there.

You can get the phpquery files, and well as read the manual at the google code page here:

  1. // load phpQuery onefile
  2. require_once('phpQuery-onefile.php');
  4. // create new pq() object
  5. phpQuery::newDocument($html);
  7. // select a specific div
  8. $div = pq('div#this-awesome-div');
  10. // select a the href of a link in a specific div
  11. $link = pq('div#this-awesome-div > a')->attr('href');
  13. // theres alot more this can do, check the manual for more.

Report this snippet  

You need to login to post a comment.