Docs For Class phpQuery

phpQuery

# Class: phpQuery

Source Location: /phpQuery.php

### Class Overview

Static namespace for phpQuery functions.

#### Author(s):

- Tobiasz Cudnik <tobiasz.cudnik/gmail.com>

### Variables

- $active
- $ajaxAllowedHosts
- $ajaxSettings
- $debug
- $defaultCharset
- $defaultDoctype
- $defaultDocumentID
- $documents
- $dumpCount
- $lastModified
- $plugins
- $pluginsLoaded
- $pluginsMethods
- $pluginsStaticMethods

### Methods

- ajax
- ajaxAllowHost
- ajaxAllowURL
- ajaxSetup
- browser
- browserGet
- browserPost
- callbackRun
- createDocumentWrapper
- debug
- DOMNodeListToArray
- each
- extend
- get
- getDocument
- getDocumentID
- getDOMDocument
- grep
- inArray
- isFunction
- isMarkup
- loadDocument
- makeArray
- map
- markupToPHP
- merge
- newDocument
- newDocumentFile
- newDocumentFileHTML
- newDocumentFilePHP
- newDocumentFileXHTML
- newDocumentFileXML
- newDocumentHTML
- newDocumentPHP
- newDocumentXHTML
- newDocumentXML
- param
- parseJSON
- php
- phpToMarkup
- plugin
- post
- pq
- selectDocument
- toJSON
- trim
- unique
- unloadDocuments
- unsafePHPTags

### Class Details

[line 33]
Static namespace for phpQuery functions.

#### Tags:

author: | Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
abstract: |

[ Top ]

### Class Variables

#### static $active = 0

[line 96]

#### Tags:

access: | public

Type: | mixed

[ Top ]

#### static $ajaxAllowedHosts = array(
'.'
)

[line 66]

Hosts allowed for AJAX connections.

Dot '.' means $_SERVER['HTTP_HOST'] (if any).

#### Tags:

access: | public

Type: | array

[ Top ]

#### static $ajaxSettings = array(
'url' => '',//TODO
'global' => true,
'type' => "GET",
'timeout' => null,
'contentType' => "application/x-www-form-urlencoded",
'processData' => true,
// 'async' => true,
'data' => null,
'username' => null,
'password' => null,
'accepts' => array(
'xml' => "application/xml, text/xml",
'html' => "text/html",
'script' => "text/javascript, application/javascript",
'json' => "application/json, text/javascript",
'text' => "text/plain",
'_default' => "*/*"
))

[line 75]

AJAX settings.

#### Tags:

var: | XXX should it be static or not ?
access: | public

Type: | array

[ Top ]

#### static $debug = false

[line 34]

#### Tags:

access: | public

Type: | mixed

[ Top ]

#### static $defaultCharset = 'UTF-8'

[line 45]

#### Tags:

access: | public

Type: | mixed

[ Top ]

#### static $defaultDoctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">'

[line 43]

Applies only to HTML.

#### Tags:

access: | public

Type: | unknown_type

[ Top ]

#### static $defaultDocumentID = null

[line 36]

#### Tags:

access: | public

Type: | mixed

[ Top ]

#### static $documents = array()

[line 35]

#### Tags:

access: | public

Type: | mixed

[ Top ]

#### static $dumpCount = 0

[line 97]

#### Tags:

access: | public

Type: | mixed

[ Top ]

#### static $lastModified = null

[line 95]

#### Tags:

access: | public

Type: | mixed

[ Top ]

#### static $plugins = array()

[line 51]

Static namespace for plugins.

#### Tags:

access: | public

Type: | object

[ Top ]

#### static $pluginsLoaded = array()

[line 57]

List of loaded plugins.

#### Tags:

access: | public

Type: | unknown_type

[ Top ]

#### static $pluginsMethods = array()

[line 58]

#### Tags:

access: | public

Type: | mixed

[ Top ]

#### static $pluginsStaticMethods = array()

[line 59]

#### Tags:

access: | public

Type: | mixed

[ Top ]

### Class Methods

### static method ajax [line 540]

`static Zend_Http_Client ajax( [array $options = array()], [ $xhr = null])`

Make an AJAX request.

#### Tags:

link: | http://docs.jquery.com/Ajax/jQuery.ajax
TODO: | $options['cache']
TODO: | $options['processData']
TODO: | support callbackStructure like each() and map()
access: | public

#### Parameters:

array | $options | See $options http://docs.jquery.com/Ajax/jQuery.ajax#toptions Additional options are: 'document' - document for global events, @see phpQuery::getDocumentID() 'referer' - implemented 'requested_with' - TODO; not implemented (X-Requested-With)
| $xhr |

[ Top ]

### static method ajaxAllowHost [line 705]

`static void ajaxAllowHost( $host1, [ $host2 = null], [ $host3 = null])`

#### Tags:

access: | public

#### Parameters:

| $host1 |
| $host2 |
| $host3 |

[ Top ]

### static method ajaxAllowURL [line 715]

`static void ajaxAllowURL( $url1, [ $url2 = null], [ $url3 = null])`

#### Tags:

access: | public

#### Parameters:

| $url1 |
| $url2 |
| $url3 |

[ Top ]

### static method ajaxSetup [line 699]

`static void ajaxSetup( $options)`

#### Tags:

access: | public

#### Parameters:

| $options |

[ Top ]

### static method browser [line 964]

`static void browser( $ajaxSettings, $callback, [ $param1 = null], [ $param2 = null], [ $param3 = null])`

#### Tags:

access: | public

#### Parameters:

| $ajaxSettings |
| $callback |
| $param1 |
| $param2 |
| $param3 |

[ Top ]

### static method browserGet [line 948]

`static void browserGet( $url, $callback, [ $param1 = null], [ $param2 = null], [ $param3 = null])`

#### Tags:

access: | public

#### Parameters:

| $url |
| $callback |
| $param1 |
| $param2 |
| $param3 |

[ Top ]

### static method browserPost [line 956]

`static void browserPost( $url, $data, $callback, [ $param1 = null], [ $param2 = null], [ $param3 = null])`

#### Tags:

access: | public

#### Parameters:

| $url |
| $data |
| $callback |
| $param1 |
| $param2 |
| $param3 |

[ Top ]

### static method callbackRun [line 868]

`static unknown_type callbackRun( $callback $callback, [$params $params = null], [$paramStructure $paramStructure = null])`

#### Tags:

access: | public

#### Parameters:

$callback | $callback | Callback
$params | $params |
$paramStructure | $paramStructure |

[ Top ]

### static method createDocumentWrapper [line 381]

`static unknown createDocumentWrapper( unknown_type $html, [ $contentType = null], [ $documentID = null], unknown_type $domId)`

Enter description here...

#### Tags:

return: | New DOM ID
todo: | support passing DOMDocument object from self::loadDocument
todo: | support PHP tags in input
access: | protected

#### Parameters:

unknown_type | $html |
unknown_type | $domId |
| $contentType |
| $documentID |

[ Top ]

### static method debug [line 521]

`static void debug( $text)`

#### Tags:

access: | public

#### Parameters:

| $text |

[ Top ]

### static method DOMNodeListToArray [line 502]

`static void DOMNodeListToArray( $DOMNodeList)`

#### Tags:

access: | public

#### Parameters:

| $DOMNodeList |

[ Top ]

### static method each [line 818]

`static unknown_type each( $object $object, $callback $callback, [ $param1 = null], [ $param2 = null], [ $param3 = null])`

#### Tags:

link: | http://docs.jquery.com/Utilities/jQuery.each
access: | public

#### Parameters:

$object | $object |
$callback | $callback |
| $param1 |
| $param2 |
| $param3 |

[ Top ]

### static method extend [line 416]

`static unknown_type extend( $class $class, [$file $file = null])`

Deprecated, use phpQuery::plugin() instead.

#### Tags:

deprecated: |
access: | public

#### Parameters:

$class | $class |
$file | $file |

[ Top ]

### static method get [line 671]

`static void get( $url, [ $data = null], [ $callback = null], [ $type = null])`

#### Tags:

access: | public

#### Parameters:

| $url |
| $data |
| $callback |
| $type |

[ Top ]

### static method getDocument [line 239]

`static phpQueryObject|queryTemplatesFetch|queryTemplatesParse|queryTemplatesPickup getDocument( [unknown_type $id = null])`

Returns document with id $id or last used as phpQueryObject.

$id can be retrived via getDocumentID() or getDocumentIDRef(). Chainable.

#### Tags:

see: | phpQuery::selectDocument()
access: | public

#### Parameters:

unknown_type | $id |

[ Top ]

### static method getDocumentID [line 754]

`static string getDocumentID( $source $source)`

Returns source's document ID.

#### Tags:

access: | public

#### Parameters:

$source | $source | DOMNode|phpQueryObject

[ Top ]

### static method getDOMDocument [line 777]

`static string getDOMDocument( $source $source)`

Get DOMDocument object related to $source.

Returns null if such document doesn't exist.

#### Tags:

access: | public

#### Parameters:

$source | $source | DOMNode|phpQueryObject|string

[ Top ]

### static method grep [line 922]

`static unknown_type grep( $array $array, $callback $callback, [$invert $invert = false])`

#### Tags:

link: | http://docs.jquery.com/Utilities/jQuery.grep
access: | public

#### Parameters:

$array | $array |
$callback | $callback |
$invert | $invert |

[ Top ]

### static method inArray [line 808]

`static void inArray( $value, $array)`

#### Tags:

access: | public

#### Parameters:

| $value |
| $array |

[ Top ]

### static method isFunction [line 941]

`static unknown_type isFunction( $function $function)`

#### Tags:

TODO: | there are problems with non-static methods, second parameter pass it but doesnt verify is method is really callable
access: | public

#### Parameters:

$function | $function |

[ Top ]

### static method isMarkup [line 518]

`static Bool isMarkup( String $input)`

Checks if $input is HTML string, which has to start with '<'.

#### Tags:

deprecated: |
todo: | still used ?
access: | public

#### Parameters:

String | $input |

[ Top ]

### static method loadDocument [line 368]

`static phpQueryObject|queryTemplatesFetch|queryTemplatesParse|queryTemplatesPick loadDocument( $document $document)`

Reuses existing DOMDocument object.

Chainable.

#### Tags:

return: | up
access: | public

#### Parameters:

$document | $document | DOMDocument

[ Top ]

### static method makeArray [line 794]

`static unknown_type makeArray( $obj)`

#### Tags:

link: | http://docs.jquery.com/Utilities/jQuery.makeArray
access: | public

#### Parameters:

| $obj |

[ Top ]

### static method map [line 836]

`static void map( $array, $callback, [ $param1 = null], [ $param2 = null], [ $param3 = null])`

#### Tags:

link: | http://docs.jquery.com/Utilities/jQuery.map
access: | public

#### Parameters:

| $array |
| $callback |
| $param1 |
| $param2 |
| $param3 |

[ Top ]

### static method markupToPHP [line 298]

`static void markupToPHP( $content)`

#### Tags:

access: | public

#### Parameters:

| $content |

[ Top ]

### static method merge [line 898]

`static void merge( array $one, array $two)`

Merge 2 phpQuery objects.

#### Tags:

todo: | node lists, phpQueryObject
access: | public

#### Parameters:

array | $one |
array | $two |

[ Top ]

### static method newDocument [line 254]

`static phpQueryObject|queryTemplatesFetch|queryTemplatesParse|queryTemplatesPickup newDocument( [unknown_type $markup = null], [ $contentType = null])`

Creates new document from markup.

Chainable.

#### Tags:

TODO: | support DOMDocument
access: | public

#### Parameters:

unknown_type | $markup |
| $contentType |

[ Top ]

### static method newDocumentFile [line 342]

`static phpQueryObject|queryTemplatesFetch|queryTemplatesParse|queryTemplatesPickup newDocumentFile( string $file, [ $contentType = null])`

Creates new document from file $file.

Chainable.

#### Tags:

access: | public

#### Parameters:

string | $file | URLs allowed. See File wrapper page at php.net for more supported sources.
| $contentType |

[ Top ]

### static method newDocumentFileHTML [line 348]

`static void newDocumentFileHTML( $file, [ $charset = 'utf-8'])`

#### Tags:

access: | public

#### Parameters:

| $file |
| $charset |

[ Top ]

### static method newDocumentFilePHP [line 357]

`static void newDocumentFilePHP( $file, [ $contentType = null])`

#### Tags:

access: | public

#### Parameters:

| $file |
| $contentType |

[ Top ]

### static method newDocumentFileXHTML [line 354]

`static void newDocumentFileXHTML( $file, [ $charset = 'utf-8'])`

#### Tags:

access: | public

#### Parameters:

| $file |
| $charset |

[ Top ]

### static method newDocumentFileXML [line 351]

`static void newDocumentFileXML( $file, [ $charset = 'utf-8'])`

#### Tags:

access: | public

#### Parameters:

| $file |
| $charset |

[ Top ]

### static method newDocumentHTML [line 260]

`static void newDocumentHTML( [ $markup = null], [ $charset = 'utf-8'])`

#### Tags:

access: | public

#### Parameters:

| $markup |
| $charset |

[ Top ]

### static method newDocumentPHP [line 271]

`static void newDocumentPHP( [ $markup = null], [ $contentType = "text/html;charset=utf-8"])`

#### Tags:

access: | public

#### Parameters:

| $markup |
| $contentType |

[ Top ]

### static method newDocumentXHTML [line 268]

`static void newDocumentXHTML( [ $markup = null], [ $charset = 'utf-8'])`

#### Tags:

access: | public

#### Parameters:

| $markup |
| $charset |

[ Top ]

### static method newDocumentXML [line 265]

`static void newDocumentXML( [ $markup = null], [ $charset = 'utf-8'])`

#### Tags:

access: | public

#### Parameters:

| $markup |
| $charset |

[ Top ]

### static method param [line 667]

`static void param( array|phpQuery $data)`

Enter description here...

#### Tags:

access: | public

#### Parameters:

array|phpQuery | $data |

[ Top ]

### static method parseJSON [line 742]

`static mixed parseJSON( string $json)`

Parses JSON into proper PHP type.

#### Tags:

access: | public

#### Parameters:

string | $json |

[ Top ]

### static method php [line 972]

`static void php( $code)`

#### Tags:

access: | public

#### Parameters:

| $code |

[ Top ]

### static method phpToMarkup [line 275]

`static void phpToMarkup( $php, [ $charset = 'utf-8'])`

#### Tags:

access: | public

#### Parameters:

| $php |
| $charset |

[ Top ]

### static method plugin [line 425]

`static void plugin( string $class, [string $file = null])`

Extend phpQuery with $class from $file.

#### Tags:

access: | public

#### Parameters:

string | $class | Extending class name. Real class name can be prepended phpQuery_.
string | $file | Filename to include. Defaults to "{$class}.php".

[ Top ]

### static method post [line 686]

`static void post( $url, [ $data = null], [ $callback = null], [ $type = null])`

#### Tags:

access: | public

#### Parameters:

| $url |
| $data |
| $callback |
| $type |

[ Top ]

### static method pq [line 131]

`static phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery|QueryTemplatesPhpQuery|false pq( string|DOMNode|DOMNodeList|array $arg1, [string|phpQueryObject|DOMNode $context = null])`

Multi-purpose function.

Use pq() as shortcut.

In below examples, $pq is any result of pq(); function.

1. Import markup into existing document (without any attaching):

- Import into selected document: pq('<div/>') // DOESNT accept text nodes at beginning of input string !
- Import into document with ID from $pq->getDocumentID(): pq('<div/>', $pq->getDocumentID())
- Import into same document as DOMNode belongs to: pq('<div/>', DOMNode)
- Import into document from phpQuery object: pq('<div/>', $pq)

2. Run query:

- Run query on last selected document: pq('div.myClass')
- Run query on document with ID from $pq->getDocumentID(): pq('div.myClass', $pq->getDocumentID())
- Run query on same document as DOMNode belongs to and use node(s)as root for query: pq('div.myClass', DOMNode)
- Run query on document from phpQuery object and use object's stack as root node(s) for query: pq('div.myClass', $pq)

#### Tags:

return: | phpQuery object or false in case of error.
access: | public

#### Parameters:

string|DOMNode|DOMNodeList|array | $arg1 | HTML markup, CSS Selector, DOMNode or array of DOMNodes
string|phpQueryObject|DOMNode | $context | DOM ID from $pq->getDocumentID(), phpQuery object (determines also query root) or DOMNode (determines also query root)

[ Top ]

### static method selectDocument [line 225]

`static void selectDocument( unknown_type $id)`

Sets default document to $id. Document has to be loaded prior to using this method.

$id can be retrived via getDocumentID() or getDocumentIDRef().

#### Tags:

access: | public

#### Parameters:

unknown_type | $id |

[ Top ]

### static method toJSON [line 729]

`static string toJSON( mixed $data)`

Returns JSON representation of $data.

#### Tags:

access: | public

#### Parameters:

mixed | $data |

[ Top ]

### static method trim [line 944]

`static void trim( $str)`

#### Tags:

access: | public

#### Parameters:

| $str |

[ Top ]

### static method unique [line 931]

`static void unique( $array)`

#### Tags:

access: | public

#### Parameters:

| $array |

[ Top ]

### static method unloadDocuments [line 485]

`static void unloadDocuments( [ $id = null], mixed $documentID)`

Unloades all or specified document from memory.

#### Tags:

access: | public

#### Parameters:

mixed | $documentID | @see phpQuery::getDocumentID() for supported types.
| $id |

[ Top ]

### static method unsafePHPTags [line 499]

`static string unsafePHPTags( phpQuery|string $content)`

Parses phpQuery object or HTML result against PHP tags and makes them active.

#### Tags:

deprecated: |
access: | public

#### Parameters:

phpQuery|string | $content |

[ Top ]

Documentation generated on Tue, 18 Nov 2008 19:39:25 +0100 by phpDocumentor 1.4.2