File tree 1 file changed +67
-0
lines changed
1 file changed +67
-0
lines changed Original file line number Diff line number Diff line change
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.
You can’t perform that action at this time.
0 commit comments