Advertisement
zero50x

span пустые убираем

May 21st, 2015
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. $html = "
  2. <h2>Наш текст</h2>
  3. <span><h2>Заголовок</h2></span>
  4. <p> Мама <span color: red;>мыла</span> раму </p>
  5. <p><span>Это абзац с чистым span'ом вокруг</span></p>
  6. <table>
  7. <tr>
  8.   <span font-size: 200%;><td>таблица</td></span>
  9. </tr>
  10. </table>
  11. <span><p> Ахуенное пати! )) </p></span>
  12. <p>The end</p>
  13. ";
  14.  
  15. $reg = '/<span>(.*?)<\/span>/ism';
  16. $run = preg_match_all($reg, $html, $matches);
  17. $count_num = count($matches[0]); // считаем кол-во элементов массива num
  18. echo "Найдено: $count_num";
  19.  
  20. for ($i = 0; $i < $count_num; $i++) {
  21.     $html = str_replace($matches[0][$i], $matches[1][$i], $html);
  22. }
  23.  
  24. print_r($html);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement