PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 1.9.7
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v1.9.7
4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.0.30 4.0.29 4.0.28 4.0.27 4.0.26 4.0.24 4.0.25 4.0.23 4.0.22 4.0.21 4.0.19 4.0.18 4.0.17 4.0.16 1.9.3 1.9.4 1.9.5 1.9.6 All 170 releases
searchpro / simplehtmldom / manual / docs / faq.md

faq.md in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript 1.9.7, at simplehtmldom/manual/docs/faq.md

60 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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);