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
+42-12Lines changed: 42 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ $doc->echo();
34
34
## How do I select nodes within my HTML document?
35
35
For this, we use `query`, or its simplified version: `Q`, as its parameter we can pass in a string with the CSS query we want, for example: `$doc->Q("div.box > span#tooltip")`.
36
36
37
-
### Html
37
+
### `$html`
38
38
39
39
```html
40
40
<ul>
@@ -48,7 +48,8 @@ For this, we use `query`, or its simplified version: `Q`, as its parameter we ca
48
48
49
49
```php
50
50
include "path/webscraper.php";
51
-
$doc = new WebScraper("<!DOCTYPE html><html><body>".$html."</body></html>");
51
+
$doc = new WebScraper();
52
+
$doc->loadHTML($html);
52
53
53
54
$doc->Q("ul li[2]");
54
55
@@ -70,7 +71,8 @@ It selects the second item in the list. We can also do the following to select m
70
71
71
72
```php
72
73
include "path/webscraper.php";
73
-
$doc = new WebScraper("<!DOCTYPE html><html><body>".$html."</body></html>");
74
+
$doc = new WebScraper();
75
+
$doc->loadHTML($html);
74
76
75
77
$doc->Q("ul li[1], ul li[3]");
76
78
@@ -93,31 +95,40 @@ That's why we have the triad: `::text`, `::attributes` and `::comment`.
93
95
94
96
<!-- TABLE OF CONTENTS -->
95
97
<detailsopen="open">
96
-
<summary>Table of Contents</summary>
98
+
<summary>List of Methods</summary>
97
99
<ol>
98
100
<li>
99
-
<a href="#introduction">About The Project</a>
101
+
<a href="#wrap-and-unwrap">wrap() and Unwrap()</a>
102
+
</li>
103
+
<li>
104
+
<a href="#addclass-and-removeclass">addClass() and removeClass()</a>
100
105
</li>
101
106
<li>
102
-
<a href="#getting-started">Getting Started</a>
107
+
<a href="#setattribute-and-removeattribute">setAttribute() and removeAttribute()</a>
103
108
</li>
104
109
<li>
105
-
<a href="#usage">Usage</a>
110
+
<a href="#html-and-text">html() and text()</a>
106
111
</li>
107
112
<li>
108
-
<a href="#roadmap">Roadmap</a>
113
+
<a href="#appendhtml-and-prependhtml">appendHtml() and prependHtml()</a>
109
114
</li>
110
115
<li>
111
-
<a href="#contributing">Contributing</a>
116
+
<a href="#hasclass-and-hasattr">hasClass() and hasAttr()</a>
112
117
</li>
113
118
<li>
114
-
<a href="#license">License</a>
119
+
<a href="#remove-and-empty">remove() and empty()</a>
115
120
</li>
116
121
<li>
117
-
<a href="#contact">Contact</a>
122
+
<a href="#hasattr-and-hasclass">hasAttr() and hasClass()</a>
118
123
</li>
119
124
<li>
120
-
<a href="#acknowledgements">Acknowledgements</a>
125
+
<a href="#replacetext-and-replacetextcallback">replaceText() and replaceTextCallback()</a>
126
+
</li>
127
+
<li>
128
+
<a href="#replacewith">replaceWith()</a>
129
+
</li>
130
+
<li>
131
+
<a href="#count">count()</a>
121
132
</li>
122
133
</ol>
123
134
</details>
@@ -704,6 +715,25 @@ Morbi in urna vel leo fringilla efficitur.</label> <label id="9">Viv
704
715
705
716
The both replacing functions above work with node texts, while `replaceWith` replaces whole HTML/XML tags.
706
717
718
+
### `$html`
719
+
```html
720
+
<p>Replace this with a header level 1 saying "I love cats' purr"</p>
721
+
```
722
+
### Php
723
+
```php
724
+
include "path/webscraper.php";
725
+
$doc = new WebScraper();
726
+
$doc->loadHTML($html);
727
+
728
+
$doc->Q("p")->replaceWith("<h1>I love cats' purr</h1>");
0 commit comments