如何使用php跳过(不允许)来自字符串的图像和视频标记

时间:2013-01-22 10:36:29

标签: php

我使用以下代码从字符串跳过图像标记, 我如何跳过图像和视频??

以下代码跳过图片代码。

使用代码:

$content = $row['Description'] ;// comes from database table

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

echo $content;

1 个答案:

答案 0 :(得分:0)

在一个preg_replace()内(未经测试)

$content = preg_replace("/<img[^>]+\>|<video[^>]+\>/i", " ", $content); 

替代方案应该绝对有用,但看起来不太好

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

修改

也许你也应该禁止使用<embed>,这用于嵌入.swf文件。