PHP的爆炸字符串排除HTML标签

时间:2018-07-31 03:48:03

标签: php explode

我有一个html内容条目。我需要用('。',$ string)爆炸。 我需要用“。”爆炸。排除html标签,并使用str_replace插入新单词,但输出包含html标签。 输入:

$string = 'abc <a href="http://x.com">x.com</a> xyz.xxx <img src="y.com" /> zyx.yyy ';

输出必须:

abc <a href="http://x.com">x.(NEWWORD)com</a> xyz.(NEWWORD)xxx <img src="y.com" /> zyx.(NEWWORD)yyy

1 个答案:

答案 0 :(得分:0)

<?php
preg_match_all("/\/?(>\s?.*?\.)\w+/i",$string, $result);

foreach($result[1] as $row)
{
   $string = str_replace($row, $row."(NEWWORD)", $string);
}

echo $string;

//Good luck!