Строитель
Добрый день! Недавно была тема про обработку тэгов <p>.
В этом примере с тэгами <th><td> как и в предыдущем случае Вы подложили отличные решения.
Большое спасибо!
Мне кажется, что в хозяйстве может пригодится функция: array InnerHTML($TagName,$html)
Спойлер (Отобразить)PHP:
скопировать код в буфер обмена
$HtmlWithP = '<body> ...some code... <p class="any_class"> <p class="any_class" anyAttribute="anyValue">Value 1</p> <p class="any_class" anyAttribute="anyValue">Value 2</p> <p class="any_class" anyAttribute="anyValue">Value 3</p> </p> <p class="any_class"> <p class="any_class" anyAttribute="anyValue">Value 4 </p> <p class="any_class" anyAttribute="anyValue">Value 5</p> </p> ...some code... </body>'; $HtmlWithDiv = '<body> ...some code... <div class="any_class"> <div class="any_class" anyAttribute="anyValue">Value 1</div> <div class="any_class" anyAttribute="anyValue">Value 2</div> <div class="any_class" anyAttribute="anyValue">Value 3</div> </div> <div class="any_class"> <div class="any_class" anyAttribute="anyValue">Value 4 </div> <div class="any_class" anyAttribute="anyValue">Value 5</div> </div> ...some code... </body>'; $HtmlWithThTd = ' <table class="guayaquil_table" border=1 width="100%"> <thead> <tr> <th>бренд</th> <th>название</th> <th>Дата</th> </tr> </thead> <tbody> <tr> <td>Febi</td> <td>Товар</td> <td>24.05.2005</td> </tr> </tbody> </table> '; function InnerHTML($TagName,$html) { preg_match_all('~<'.$TagName.'[^>]*>([\w\.]+\s*\d*)\s*</'.$TagName.'>~iu', $html, $a); return $a[1]; } $a=InnerHTML("p",$HtmlWithP); echo '<pre>Examle 1 Html with tag p<br>'; var_dump($a); echo '</pre>'; $a=InnerHTML("div",$HtmlWithDiv); echo '<pre>Examle 2 Html with tag div<br>'; var_dump($a); echo '</pre>'; $a=InnerHTML("th",$HtmlWithThTd); echo '<pre>Examle 3.1 Html with tag th<br>'; var_dump($a); echo '</pre>'; $b=InnerHTML("td",$HtmlWithThTd); echo '<pre>Examle 3.2 Html with tag td<br>'; var_dump($b); echo '</pre>'; echo '<pre>Examle 3.3 array_combine for tags th and td<br>'; var_dump($arr); echo '</pre>'; /* Example 1 Html with tag p array(5) { [0]=> string(7) "Value 1" [1]=> string(7) "Value 2" [2]=> string(7) "Value 3" [3]=> string(7) "Value 4" [4]=> string(7) "Value 5" } Example 2 Html with tag div array(5) { [0]=> string(7) "Value 1" [1]=> string(7) "Value 2" [2]=> string(7) "Value 3" [3]=> string(7) "Value 4" [4]=> string(7) "Value 5" } Example 3.1 Html with tag th array(3) { [0]=> string(10) "бренд" [1]=> string(16) "название" [2]=> string(8) "Дата" } Example 3.2 Html with tag td array(3) { [0]=> string(4) "Febi" [1]=> string(10) "Товар" [2]=> string(10) "24.05.2005" } Example 3.3 array_combine for tags th and td array(3) { ["бренд"]=> string(4) "Febi" ["название"]=> string(10) "Товар" ["Дата"]=> string(10) "24.05.2005" } */
Demo: https://www[dot]alto-booking[dot]com/test/p.php
|