PHP-删除< img>字符串中的标签 [英] PHP - remove <img> tag from string
本文介绍了PHP-删除< img>字符串中的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,我需要删除字符串中的所有图像,但我找不到正确的方法.
Hey, I need to delete all images from a string and I just can't find the right way to do it.
这是我尝试过的方法,但是不起作用:
Here is what I tryed, but it doesn't work:
preg_replace("/<img[^>]+\>/i", "(image) ", $content);
echo $content;
有什么想法吗?
推荐答案
尝试将\
放在>
前面.
我刚刚测试了您的正则表达式,它工作正常.这就是我用的:
I just tested your regex and it works fine. This is what I used:
<?
$content = "this is something with an <img src=\"test.png\"/> in it.";
$content = preg_replace("/<img[^>]+\>/i", "(image) ", $content);
echo $content;
?>
结果是:
this is something with an (image) in it.
这篇关于PHP-删除< img>字符串中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文