You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,6 +57,36 @@ This example loads the html from big.html, a real page found online, and gets al
57
57
58
58
Alternativly, you can always use the load() method to load the file. It will attempt to find the file using file_exists and, if succesfull, will call loadFromFile() for you. The same applies to a URL and loadFromUrl() method.
59
59
60
+
Example With Url
61
+
----------------
62
+
63
+
Loading a url is very similar to the way you would load the html from a file.
64
+
65
+
```php
66
+
use PHPHtmlParser\Dom;
67
+
68
+
$dom = new Dom;
69
+
$dom->loadFromUrl('http://google.com');
70
+
$html = $dom->outerHtml;
71
+
72
+
// or
73
+
$dom->load('http://google.com');
74
+
$html = $dom->outerHtml; // same result as the first example
75
+
```
76
+
77
+
What makes the loadFromUrl method note worthy is the PHPHtmlParser\CurlInterface parameter, an optional second parameter. By default, we use the PHPHtmlParser\Curl class to get the contents of the url. On the other hand, though, you can inject your own implementation of CurlInterface and we will attempt to load the url using what ever tool/settings you want, up to you.
78
+
79
+
```php
80
+
use PHPHtmlParser\Dom;
81
+
use App\Services\Connector;
82
+
83
+
$dom = new Dom;
84
+
$dom->loadFromUrl('http://google.com', new Connector);
85
+
$html = $dom->outerHtml;
86
+
```
87
+
88
+
As long as the Connector object implements the PHPHtmlParser\CurlInterface interface properly it will use that object to get the content of the url instead of the default PHPHtmlParser\Curl class.
0 commit comments