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
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,8 @@ Usage
20
20
You can find many examples of how to use the dom parser and any of its parts (which you will most likely never touch) in the tests directory. The tests are done using PHPUnit and are very small, a few lines each, and are a great place to start. Given that, I'll still be showing a few examples of how the package should be used. The following example is a very simplistic usage of the package.
21
21
22
22
```php
23
+
// Assuming you installed from Composer:
24
+
require "vendor/autoload.php";
23
25
use PHPHtmlParser\Dom;
24
26
25
27
$dom = new Dom;
@@ -36,6 +38,8 @@ Loading Files
36
38
You may also seamlessly load a file into the dom instead of a string, which is much more convinient and is how I except most developers will be loading the html. The following example is taken from our test and uses the "big.html" file found there.
37
39
38
40
```php
41
+
// Assuming you installed from Composer:
42
+
require "vendor/autoload.php";
39
43
use PHPHtmlParser\Dom;
40
44
41
45
$dom = new Dom;
@@ -67,6 +71,8 @@ Loading Url
67
71
Loading a url is very similar to the way you would load the html from a file.
68
72
69
73
```php
74
+
// Assuming you installed from Composer:
75
+
require "vendor/autoload.php";
70
76
use PHPHtmlParser\Dom;
71
77
72
78
$dom = new Dom;
@@ -81,6 +87,8 @@ $html = $dom->outerHtml; // same result as the first example
81
87
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.
82
88
83
89
```php
90
+
// Assuming you installed from Composer:
91
+
require "vendor/autoload.php";
84
92
use PHPHtmlParser\Dom;
85
93
use App\Services\Connector;
86
94
@@ -97,6 +105,8 @@ Loading Strings
97
105
Loading a string directly, with out the checks in `load()` is also easely done.
98
106
99
107
```php
108
+
// Assuming you installed from Composer:
109
+
require "vendor/autoload.php";
100
110
use PHPHtmlParser\Dom;
101
111
102
112
$dom = new Dom;
@@ -112,6 +122,8 @@ Options
112
122
You can also set parsing option that will effect the behavior of the parsing engine. You can set a global option array using the `setOptions` method in the `Dom` object or a instance specific option by adding it to the `load` method as an extra (optional) parameter.
0 commit comments