PHP - 从字符串中删除 <img> 标签

标签 php string

嘿,我需要从字符串中删除所有图像,但我找不到正确的方法。

这是我尝试过的,但它不起作用:

preg_replace("/<img[^>]+\>/i", "(image) ", $content);
echo $content;

有什么想法吗?

最佳答案

尝试将 \ 放在 > 前面。

编辑:我刚刚测试了你的正则表达式,它工作正常。这是我用的:

<?
    $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> 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1107194/

相关文章:

字符串替换中的 C++ 错误

php - 如何在 PHP 中的数字之间插入连字符?

C++ - str(n)cmp(i) () 用于 C++ 样式字符串

ruby - 保存字符串的某一段

php - 使用空数组作为执行参数

python - 我如何从这个字符串中挑选?

javascript - 使用 PHP 将 PDF 转为 jpg

php - 如何在 mySQL 或 PHP 上根据日期对输出行进行分组?

javascript - 数据库表更改/更新/删除时触发的 jQuery 事件

javascript - 如何根据 echo 使用 Javascript 重定向 PHP 表单