[英]php regular expression find and replace all except anchor and images tags
<p> $ html =“这是一个锚点,再次转到<p>和此图像”; </ p> <p>找到'this'并用'一个新单词'替换,结果将是</ p> <p> ///新单词是锚点,再次转到<p>并用新单词图像替换锚点和图像标签以外的所有内容</ p>
Your code needs to be properly formatted so it is readable. 您的代码需要正确格式化,以便可读。
As for the regex, you don't need it, you can use strip_tags()
with the second parameter: 至于正则表达式,则不需要它,可以将
strip_tags()
与第二个参数一起使用:
$text = '<a href="">link<img src=""></a><span>some text</span>';
echo strip_tags($text, '<a><img>');
The second parameter in strip_tags tells the function what tags you want to keep, in this case, tags and tags. strip_tags中的第二个参数告诉函数您要保留哪些标签,在这种情况下为标签和标签。
That is to replace actual tags. 那就是替换实际的标签。
To replace words, use str_ireplace()
要替换单词,请使用
str_ireplace()
$text = 'this is a link, this is an image';
echo str_ireplace('this', 'new word', $text);
// Outputs:
new word is a link, new word is an image
If you need a different answer, try re-phrasing your original question to make it more informative 如果您需要其他答案,请尝试重新措辞您原来的问题,以使其内容更丰富
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.