Skip to content

Commit da7c5f8

Browse files
Create replacewith.md
1 parent c5de38e commit da7c5f8

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

manual/replacewith.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# `replaceWith`
2+
3+
<a href="replacetext-and-replacetextcallback.md"><b><< Previous</b></a>
4+
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
5+
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
6+
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
7+
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
8+
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
9+
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
10+
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
11+
&emsp;&emsp;&emsp;&emsp;
12+
<a href="start.md"><b>Start >></b></a>
13+
14+
The `replaceWith()` method replaces selected elements with new HTML content.
15+
16+
## Syntax: `replaceWith`
17+
18+
```php
19+
$doc->Q([selector])->replaceWith([html/xml-content]);
20+
```
21+
22+
### `$html`
23+
24+
```html
25+
<div class="container">
26+
<div class="inner first">Hello</div>
27+
<div class="inner second">And</div>
28+
<div class="inner third">Goodbye</div>
29+
</div>
30+
```
31+
32+
<details>
33+
<summary>
34+
<b>Php</b>
35+
</summary>
36+
37+
```php
38+
<?php
39+
include "../src/webparser.php";
40+
$doc = new WebParser();
41+
$doc->loadHTML($html);
42+
43+
$doc->Q("div.second")->replaceWith("<h2>New heading</h2>");
44+
45+
$doc->output();
46+
```
47+
48+
</details>
49+
50+
<details>
51+
<summary>
52+
<b>Output</b>
53+
</summary>
54+
55+
```html
56+
<div class="container">
57+
<div class="inner first">Hello</div>
58+
<h2>New heading</h2>
59+
<div class="inner third">Goodbye</div>
60+
</div>
61+
```
62+
63+
</details>
64+
65+
## Example test code snippet
66+
67+
Click [here](../examples/example_replace_with.php) to go to example test.

0 commit comments

Comments
 (0)