PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 1.9.6
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v1.9.6
4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.0.30 4.0.29 4.0.28 4.0.27 4.0.26 4.0.24 4.0.25 4.0.23 4.0.22 4.0.21 4.0.19 4.0.18 4.0.17 4.0.16 1.9.3 1.9.4 1.9.5 1.9.6 All 170 releases
searchpro / simplehtmldom / example / example_advanced_selector.php

example_advanced_selector.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript 1.9.6, at simplehtmldom/example/example_advanced_selector.php

54 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // example of how to use advanced selector features
3 include('../simple_html_dom.php');
4
5 // -----------------------------------------------------------------------------
6 // descendant selector
7 $str = <<<HTML
8 <div>
9 <div>
10 <div class="foo bar">ok</div>
11 </div>
12 </div>
13 HTML;
14
15 $html = str_get_html($str);
16 echo $html->find('div div div', 0)->innertext . '<br>'; // result: "ok"
17
18 // -----------------------------------------------------------------------------
19 // nested selector
20 $str = <<<HTML
21 <ul id="ul1">
22 <li>item:<span>1</span></li>
23 <li>item:<span>2</span></li>
24 </ul>
25 <ul id="ul2">
26 <li>item:<span>3</span></li>
27 <li>item:<span>4</span></li>
28 </ul>
29 HTML;
30
31 $html = str_get_html($str);
32 foreach($html->find('ul') as $ul) {
33 foreach($ul->find('li') as $li)
34 echo $li->innertext . '<br>';
35 }
36
37 // -----------------------------------------------------------------------------
38 // parsing checkbox
39 $str = <<<HTML
40 <form name="form1" method="post" action="">
41 <input type="checkbox" name="checkbox1" value="checkbox1" checked>item1<br>
42 <input type="checkbox" name="checkbox2" value="checkbox2">item2<br>
43 <input type="checkbox" name="checkbox3" value="checkbox3" checked>item3<br>
44 </form>
45 HTML;
46
47 $html = str_get_html($str);
48 foreach($html->find('input[type=checkbox]') as $checkbox) {
49 if ($checkbox->checked)
50 echo $checkbox->name . ' is checked<br>';
51 else
52 echo $checkbox->name . ' is not checked<br>';
53 }
54 ?>