Skip to content

Commit 1a1b476

Browse files
Update README.md
1 parent 70df566 commit 1a1b476

1 file changed

Lines changed: 42 additions & 12 deletions

File tree

README.md

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ $doc->echo();
3434
## How do I select nodes within my HTML document?
3535
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")`.
3636

37-
### Html
37+
### `$html`
3838

3939
```html
4040
<ul>
@@ -48,7 +48,8 @@ For this, we use `query`, or its simplified version: `Q`, as its parameter we ca
4848

4949
```php
5050
include "path/webscraper.php";
51-
$doc = new WebScraper("<!DOCTYPE html><html><body>".$html."</body></html>");
51+
$doc = new WebScraper();
52+
$doc->loadHTML($html);
5253

5354
$doc->Q("ul li[2]");
5455

@@ -70,7 +71,8 @@ It selects the second item in the list. We can also do the following to select m
7071

7172
```php
7273
include "path/webscraper.php";
73-
$doc = new WebScraper("<!DOCTYPE html><html><body>".$html."</body></html>");
74+
$doc = new WebScraper();
75+
$doc->loadHTML($html);
7476

7577
$doc->Q("ul li[1], ul li[3]");
7678

@@ -93,31 +95,40 @@ That's why we have the triad: `::text`, `::attributes` and `::comment`.
9395

9496
<!-- TABLE OF CONTENTS -->
9597
<details open="open">
96-
<summary>Table of Contents</summary>
98+
<summary>List of Methods</summary>
9799
<ol>
98100
<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>
100105
</li>
101106
<li>
102-
<a href="#getting-started">Getting Started</a>
107+
<a href="#setattribute-and-removeattribute">setAttribute() and removeAttribute()</a>
103108
</li>
104109
<li>
105-
<a href="#usage">Usage</a>
110+
<a href="#html-and-text">html() and text()</a>
106111
</li>
107112
<li>
108-
<a href="#roadmap">Roadmap</a>
113+
<a href="#appendhtml-and-prependhtml">appendHtml() and prependHtml()</a>
109114
</li>
110115
<li>
111-
<a href="#contributing">Contributing</a>
116+
<a href="#hasclass-and-hasattr">hasClass() and hasAttr()</a>
112117
</li>
113118
<li>
114-
<a href="#license">License</a>
119+
<a href="#remove-and-empty">remove() and empty()</a>
115120
</li>
116121
<li>
117-
<a href="#contact">Contact</a>
122+
<a href="#hasattr-and-hasclass">hasAttr() and hasClass()</a>
118123
</li>
119124
<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>
121132
</li>
122133
</ol>
123134
</details>
@@ -704,6 +715,25 @@ Morbi in urna vel leo fringilla efficitur.&lt;/label&gt; &lt;label id="9"&gt;Viv
704715

705716
The both replacing functions above work with node texts, while `replaceWith` replaces whole HTML/XML tags.
706717

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>");
729+
730+
$doc->echo();
731+
```
732+
### Output
733+
```html
734+
<h1>I love cats' purr</h1>
735+
```
736+
707737
## `count`
708738

709739
It counts occurrences of tag.

0 commit comments

Comments
 (0)