Skip to content
tobiasz.cudnik edited this page Sep 22, 2008 · 18 revisions

Although *phpQuery* is *jQuery* port, there is extensive PHP-specific support.

Actually there are 3 major sections.

Table of Contents

PHP Interfaces

phpQuery implements some of Standard PHP Library (SPL) interfaces.

Iterator interface

Iterator interface allows looping objects thou native PHP foreach loop. Example:

Now there is a catch above. Foreach loop *doesn't return phpQuery object*. Instead it returns pure DOMNode. That's how jQuery does, because not always you need *phpQuery* when you found interesting nodes.

ArrayAccess interface

If you like writing arrays, with phpQuery you can still do it, thanks to the ArrayAccess interface.

Countable interface

If used to do `count($something)` you can still do this that way, instead of eg `pq('p')->size()`.

Callbacks

There is a special Callback wiki section.

PHP Code Injection

Additional methods allows placing PHP code inside DOM.

 * *`attrPHP($attr, $code)`* equals to `attr($attr, "<?php $code ?>")`
 * *`addClassPHP($code)`* equals to `addClass("<?php $code ?>")`
 * *`beforePHP($code)`* equals to `before("<?php $code ?>")`
 * *`afterPHP($code)`* equals to `after("<?php $code ?>")`
 * *`prependPHP($code)`* equals to `prepend("<?php $code ?>")`
 * *`appendPHP($code)`* equals to `append("<?php $code ?>")`
 * *`php($code)`* equals to `html("<?php $code ?>")`
 * *`wrapAllPHP($codeBefore, $codeAfter)`* equals to `html("<?php $code ?>")`
 * *`wrapPHP($codeBefore, $codeAfter)`* equals to `html("<?php $code ?>")`
 * *`wrapInnerPHP($codeBefore, $codeAfter)`* equals to `html("<?php $code ?>")`

PHP Tags

Methods from section above doesn't inject runnable code. For safety reasons, file (or it's content) need to be passed thru *`phpQuery::unsafePHPTags()`* method. This can be done only once, just before outputting the content, because return value is just a *string* not *phpQuery object*.

Clone this wiki locally