-
Notifications
You must be signed in to change notification settings - Fork 3
PHPSupport
Although *phpQuery* is *jQuery* port, there is extensive PHP-specific support.
Actually there are 3 major sections.
phpQuery implements some of Standard PHP Library (SPL) interfaces.
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.
If you like writing arrays, with phpQuery you can still do it, thanks to the ArrayAccess interface.
If used to do `count($something)` you can still do this that way, instead of eg `pq('p')->size()`.
There is a special Callback wiki section.
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 ?>")`
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*.