| 1 |
# FAQ |
| 2 |
|
| 3 |
## Problem with finding |
| 4 |
|
| 5 |
Q: Element not found in such case: `$html->find('div[style=padding: 0px 2px;] span[class=rf]');` |
| 6 |
|
| 7 |
A: If there is blank in selectors, quote it! |
| 8 |
$html->find('div[style="padding: 0px 2px;"] span[class=rf]'); |
| 9 |
|
| 10 |
## Problem with hosting |
| 11 |
|
| 12 |
Q: On my local server everything works fine, but when I put it on my esternal server it doesn't work. |
| 13 |
|
| 14 |
A: The "file_get_dom" function is a wrapper of "file_get_contents" function, you must set "allow_url_fopen" as TRUE in "php.ini" to allow accessing files via HTTP or FTP. However, some hosting venders disabled PHP's "allow_url_fopen" flag for security issues... PHP provides excellent support for "curl" library to do the same job, Use curl to get the page, then call "str_get_dom" to create DOM object. |
| 15 |
|
| 16 |
Example: |
| 17 |
|
| 18 |
$curl = curl_init(); |
| 19 |
curl_setopt($curl, CURLOPT_URL, 'http://????????'); |
| 20 |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
| 21 |
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); |
| 22 |
$str = curl_exec($curl); |
| 23 |
curl_close($curl); |
| 24 |
|
| 25 |
$html= str_get_html($str); |
| 26 |
... |
| 27 |
|
| 28 |
## Behind a proxy |
| 29 |
|
| 30 |
Q: My server is behind a Proxy and i can't use file_get_contents b/c it returns a unauthorized error. |
| 31 |
|
| 32 |
A: Thanks for Shaggy to provide the solution: |
| 33 |
|
| 34 |
// Define a context for HTTP. |
| 35 |
$context = array |
| 36 |
( |
| 37 |
'http' => array |
| 38 |
( |
| 39 |
'proxy' => 'addresseproxy:portproxy', // This needs to be the server and the port of the NTLM Authentication Proxy Server. |
| 40 |
'request_fulluri' => true, |
| 41 |
), |
| 42 |
); |
| 43 |
|
| 44 |
$context = stream_context_create($context); |
| 45 |
|
| 46 |
$html= file_get_html('http://www.php.net', false, $context); |
| 47 |
... |
| 48 |
|
| 49 |
## Memory leak |
| 50 |
|
| 51 |
Q: This script is leaking memory seriously... After it finished running, it's not cleaning up dom object properly from memory.. |
| 52 |
|
| 53 |
A: Due to php5 circular references memory leak, after creating DOM object, you must call $dom->clear() to free memory if call file_get_dom() more then once. |
| 54 |
|
| 55 |
Example: |
| 56 |
|
| 57 |
$html = file_get_html(...); |
| 58 |
// do something... |
| 59 |
$html->clear(); |
| 60 |
unset($html); |