Overview
  • Class

Classes

  • hQuery
  • hQuery_Element
  • hQuery_HTML_Parser
  • hQuery_Node

Class hQuery

Main Class, represents an HTML document.

hQuery_Node implements Iterator, Countable
Extended by hQuery_HTML_Parser
Extended by hQuery
License: MIT
Author: Dumitru Uzun (DUzun.ME)
Located at

Methods summary

public static hQuery
# fromHTML( string $html, string $url = NULL )

Parse and HTML string.

Parse and HTML string.

Parameters

$html
  • source of some HTML document
$url
  • OPTIONAL location of the document. Used for relative URLs inside the document.

Returns

hQuery
$doc
public static hQuery
# fromFile( string $filename, boolean $use_include_path = false, resource $context = NULL )

Read the HTML document from a file.

Read the HTML document from a file.

Parameters

$filename
  • a valid filename
$use_include_path
  • OPTIONAL passed to file_get_contents()
$context
  • OPTIONAL A valid context resource created with stream_context_create().

Returns

hQuery
$doc
public static hQuery
# fromURL( string $url, array $headers = NULL, array|string $body = NULL, array $options = NULL )

Fetch the HTML document from remote $url.

Fetch the HTML document from remote $url.

Parameters

$url
  • the URL of the document
$headers
  • OPTIONAL request headers
$body
  • OPTIONAL body of the request (for POST or PUT)
$options
  • OPTIONAL request options (see self::http_wr() for more details)

Returns

hQuery
$doc
public hQuery_Element
# find( string $sel, array|string $attr = NULL, hQuery_Node $ctx = NULL )

Finds a collection of nodes inside current document/context (similar to jQuery.fn.find()).

Finds a collection of nodes inside current document/context (similar to jQuery.fn.find()).

Parameters

$sel
  • A valid CSS selector.
$attr
  • OPTIONAL attributes as string or key-value pairs.
$ctx
  • OPTIONAL the context where to search. If omitted, $this is used.

Returns

hQuery_Element
collection of matched elements

Overrides

hQuery_Node::find
public array
# find_html( string $sel, array|string $attr = NULL, hQuery_Node $ctx = NULL )

Combination of ->find() + ->html()

Combination of ->find() + ->html()

Parameters

$sel
  • A valid CSS selector.
$attr
  • OPTIONAL attributes as string or key-value pairs.
$ctx
  • OPTIONAL the context where to search. If omitted, $this is used.

Returns

array
list of HTML contents of all matched elements
public array
# find_text( string $sel, array|string $attr = NULL, hQuery_Node $ctx = NULL )

Combination of ->find() + ->text()

Combination of ->find() + ->text()

Parameters

$sel
  • A valid CSS selector.
$attr
  • OPTIONAL attributes as string or key-value pairs.
$ctx
  • OPTIONAL the context where to search. If omitted, $this is used.

Returns

array
list of Text contents of all matched elements
public
# index( )

Index elements of the source HTML. (Called automatically)

Index elements of the source HTML. (Called automatically)

public static string
# jsonize( mixed $data, &string & $type = NULL, $ops = 0 )

Serialize $data as JSON, fallback to serialize.

Serialize $data as JSON, fallback to serialize.

Parameters

$data
  • the data to be serialized
$type
  • returns the serialization method used ('json' | 'ser')
$ops

Returns

string
the serialized data
public static mixed
# unjsonize( string $str, &string & $type = NULL )

Unserialize $data from either JSON or serialize.

Unserialize $data from either JSON or serialize.

Parameters

$str
  • the data to be unserialized
$type
  • if not set, returns the serialization method detected ('json' | 'ser'); if set, forces unjsonize() to use this method for unserialization.

Returns

mixed
the unserialized data
protected static string
# serjstype( string $str )

Tries to detect format of $str (json or ser).

Tries to detect format of $str (json or ser).

Parameters

$str
  • JSON encoded or PHP serialized data.

Returns

string
'json' | 'ser', or FALSE on failure to detect format.
public static
# gzdecode( $str )

gzdecode() (for PHP < 5.4.0)

gzdecode() (for PHP < 5.4.0)

protected static
# _gzdecode( $data )

Alternative gzdecode() (for PHP < 5.4.0) source: http://nl1.php.net/manual/en/function.gzdecode.php#82879

Alternative gzdecode() (for PHP < 5.4.0) source: http://nl1.php.net/manual/en/function.gzdecode.php#82879

protected static array
# get_cache( string $fn, integer $expire = false, boolean $meta_only = false )

Read data from a cache file.

Read data from a cache file.

Parameters

$fn
  • cache filename
$expire
  • OPTIONAL contents returned only if it is newer then $expire seconds
$meta_only
  • OPTIONAL if TRUE, read only meta-info (faster)

Returns

array
[mixed , array ]
protected static integer|boolean
# set_cache( string $fn, mixed $cnt, array $meta = NULL, boolean $gzip = true )

Save data to a cache file.

Save data to a cache file.

Parameters

$fn
  • cache filename
$cnt
  • contents to be cached
$meta
  • OPTIONAL meta information related to contents.
$gzip
  • OPTIONAL if TRUE and gzip supported, store contents gzipped

Returns

integer|boolean
On success, number of written bytes, FALSE on fail.
public static true
# do_flock( resource $fp, integer $lock, integer $timeout_ms = 384 )

Lock with retries

Lock with retries

Parameters

$fp
  • Open file pointer
$lock
  • Lock type
$timeout_ms
  • OPTIONAL Timeout to wait for unlock in miliseconds

Returns

true
on success, false on fail

Author

Dumitru Uzun
public static
# flock_put_contents( $fn, $cnt, $block = false )
public static
# flock_get_contents( $fn, $block = false )
public static boolean
# is_url_path( string $path )

Check whether $path is a valid url.

Check whether $path is a valid url.

Parameters

$path
  • a path to check

Returns

boolean
TRUE if $path is a valid URL, FALSE otherwise
public static boolean
# is_abs_path( string $path )

Check whether $path is an absolute path.

Check whether $path is an absolute path.

Parameters

$path
  • a path to check

Returns

boolean
TRUE if $path is an absolute path, FALSE otherwise
public static string
# abs_url( string $url, string $base )

Given a $url (relative or absolute) and a $base url, returns absolute url for $url.

Given a $url (relative or absolute) and a $base url, returns absolute url for $url.

Parameters

$url
  • relative or absolute URL
$base
  • Base URL for $url

Returns

string
absolute URL for $url
public static
# parse_cookie( $str )
public static array
# http_wr( string $host, array $head = NULL, mixed $body = NULL, array $options = NULL )

Executes a HTTP write-read session.

Executes a HTTP write-read session.

Parameters

$host
  • IP/HOST address or URL
$head
  • list off HTTP headers to be sent along with the request to $host
$body
  • data to be sent as the contents of the request. If is array or object, a http query is built.
$options
  • list of option as key-value: timeout - connection timeout in seconds host - goes to headers, overrides $host (ex. $host == '127.0.0.1', $options['host'] == 'www.example.com') port - useful when $host is not a full URL scheme - http, ssl, tls, udp, ... close - whether to close connection o not redirects - number of allowed redirects redirect_method - if (string), this is the new method for redirect request, else if true, preserve method, else use 'GET' on redirect. by default preserve on 307 and 308, GET on 301-303

Returns

array
[contents, headers, http-status-code, http-status-message]

Author

Dumitru Uzun

Methods inherited from hQuery_HTML_Parser

__construct(), __get(), __set(), __toString(), _find(), _get_ctx(), _index_all(), _index_comments_html(), _info(), baseURI(), detect_charset(), filter(), get_aids_byAttr(), get_aids_byClass(), get_aids_byClassAttr(), get_attr_byAid(), get_attr_byId(), get_ids_byAid(), get_ids_byAttr(), get_ids_byClass(), get_ids_byClassAttr(), get_url_base(), get_url_path(), hasClass(), location(), strlen(), substr(), url2abs()

Methods inherited from hQuery_Node

CSSArr2Str(), __destruct(), __isset(), __unset(), _all(), _children(), _ctx_ids(), _doc_ids(), _filter(), _has(), _my_ids(), _next(), _parent(), _prev(), _sub_ids(), array_select(), attr(), convert_encoding(), count(), current(), doc(), exclude(), html(), html_attr2str(), html_findTagClose(), html_parseAttrStr(), isDoc(), isEmpty(), is_empty(), key(), next(), nodeName(), outerHtml(), parseCSStr(), pos(), prev(), rewind(), str_range(), text(), valid()

Constants summary

Constants inherited from hQuery_Node

VERSION

Properties summary

public $headers
#
public static $cache_path
#
public static integer $cache_expires
# 3600
public static $_mockup_class
#

Properties inherited from hQuery_HTML_Parser

$_emptyTags, $_icharset, $_index_attribs, $_specialTags, $_tagID_first_letter, $_tagID_letters, $_unparsedTags, $_url_attribs, $attr_idx, $attribs, $attrs, $autoclose_tags, $case_folding, $class_idx, $del_spaces, $html, $idx_attr, $indexed, $o, $tag_idx, $tags

Properties inherited from hQuery_Node

$_ar_, $_fl_, $_mi_, $_nl_, $_prop, $_tr_, $doc, $exc, $ids, $last_http_result, $selected_doc, $tag_map

API documentation generated by ApiGen