嘿,我需要从一个字符串中删除所有的图片,但是我找不到正确的方法来实现它。
这是我尝试过的方法,但它并没有起作用:
preg_replace("/<img[^>]+\>/i", "(image) ", $content);
echo $content;
有什么想法吗?
嘿,我需要从一个字符串中删除所有的图片,但是我找不到正确的方法来实现它。
这是我尝试过的方法,但它并没有起作用:
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;
?>
结果为:
这是一个包含(图片)的东西。
preg_replace("/<img[^>]+\>/i", "(image) ", $content);
这与实际问题有何不同? - fat_mike$content
,因为 preg_replace
不会修改原始字符串。$content = preg_replace("/<img[^>]+\>/i", "(image) ", $content);
Sean,它可以正常工作,我刚刚使用了这段代码。
$content = preg_replace("/<img[^>]+\>/i", " ", $content);
echo $content;
//结果只有纯文本。它有效!!!
$news = $row_latest_news ['content'];
$news = preg_replace("/<img[^>]+\>/i", "", $news);
if (strlen($news) > 300){
echo substr($news, 0, strpos($news,' ',300)).'...';
}
else {
echo $news;
}
$this->load->helper('security');
$h=mysql_real_escape_string(strip_image_tags($comment));
<img src="#">在数据库表中只需插入此 # 字符。
只需使用CodeIgniter的form_validation类:
strip_image_tags($str).
$this->load->library('form_validation');
$this->form_validation->set_rules('nombre_campo', 'label', 'strip_image_tags');