嘿,我需要从字符串中删除所有图像,但我找不到正确的方法.
这是我尝试过的,但它不起作用:
preg_replace("/<img[^>]+\>/i", "(image) ", $content);
echo $content;
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
Sea*_*ght 144
试着放在\前面>.
编辑:我刚测试你的正则表达式,它工作正常.这是我用过的:
<?
$content = "this is something with an <img src=\"test.png\"/> in it.";
$content = preg_replace("/<img[^>]+\>/i", "(image) ", $content);
echo $content;
?>
Run Code Online (Sandbox Code Playgroud)
结果是:
this is something with an (image) in it.
Joh*_*ica 18
您需要将结果分配回来,$content因为preg_replace不会修改原始字符串.
$content = preg_replace("/<img[^>]+\>/i", "(image) ", $content);
Run Code Online (Sandbox Code Playgroud)
小智 7
肖恩它工作正常我刚刚使用此代码
$content = preg_replace("/<img[^>]+\>/i", " ", $content);
echo $content;
Run Code Online (Sandbox Code Playgroud)
//结果它只是纯文本.有用!!!
| 归档时间: |
|
| 查看次数: |
114490 次 |
| 最近记录: |