Return to Snippet

Revision: 55591
at February 13, 2012 09:55 by FatFolderDesigner


Initial Code
// load phpQuery onefile
require_once('phpQuery-onefile.php');

// create new pq() object
phpQuery::newDocument($html);

// select a specific div
$div = pq('div#this-awesome-div');

// select a the href of a link in a specific div
$link = pq('div#this-awesome-div > a')->attr('href');

// theres alot more this can do, check the manual for more.

Initial URL
http://fatfolderdesign.com/544/php/basics-of-phpquery-jquery-style-dom-selection-in-php

Initial Description
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: http://code.google.com/p/phpquery/

Initial Title
jQuery syle DOM navigation in PHP with phpQuery

Initial Tags
php, DOM

Initial Language
PHP