Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从标记中删除所有图像拍摄选项(alt、class、样式等)_Php_Html_Css_Image_Str Replace - Fatal编程技术网

Php 从标记中删除所有图像拍摄选项(alt、class、样式等)

Php 从标记中删除所有图像拍摄选项(alt、class、样式等),php,html,css,image,str-replace,Php,Html,Css,Image,Str Replace,我有一个网站,人们可以复制和粘贴直接从网页到我的。然后将其保存到我的数据库中 目前,我只计划让用户使用我的图像插入工具,该工具将图像保存为基本html图像标记: <img src="www.linktomimage.com"/> 在回显这些数据时,我会使用strreplace将任何BBcode[img]标记更改为html图像标记,以便它们能够正确显示 然而,我知道,用户可以直接从页面上复制,因为图像标签可以包装在各种标签中 2比较: <img src="http://

我有一个网站,人们可以复制和粘贴直接从网页到我的。然后将其保存到我的数据库中

目前,我只计划让用户使用我的图像插入工具,该工具将图像保存为基本html图像标记:

  <img src="www.linktomimage.com"/>
在回显这些数据时,我会使用strreplace将任何BBcode[img]标记更改为html图像标记,以便它们能够正确显示

然而,我知道,用户可以直接从页面上复制,因为图像标签可以包装在各种标签中

2比较:

  <img src="http://AN IMAGE LINK URL" border="0" alt="" />

以及:


许多不同的论坛使用不同的版本

我的问题是如何删除这些图像链接中的所有内容,然后将url放入我自己的url中:

  <img class="buildimage" src="http://my image">

我想不出使用str_replace()的方法,因为有太多不同的变体

希望这是有意义的

作为参考,我目前使用它将[img]标记更改为html并添加我的类:

    $text = str_replace("[IMG]", "<img class='buildimage' src='", "$text");
$text = str_replace("[/IMG]", "'>", "$text");
$text=str_replace(“[IMG]”,“”,“$text”);

谢谢!Craig.

您可以使用正则表达式从字符串中获取src:

$string = '<img border="0" src="/images/sampleimage.jpg" alt="Image" width="100" height="100" />';

preg_match('/<img(.*)src(.*)=(.*)"(.*)"/U', $string, $result);

$foo = array_pop($result);
$string='';

preg_match('/您可以在页面上使用JavaScript和输入来删除除src之外的所有属性吗?您可以使用DOM解析器,获取所需的属性,并使用这些属性构建新的图像标记。
    $text = str_replace("[IMG]", "<img class='buildimage' src='", "$text");
$text = str_replace("[/IMG]", "'>", "$text");
$string = '<img border="0" src="/images/sampleimage.jpg" alt="Image" width="100" height="100" />';

preg_match('/<img(.*)src(.*)=(.*)"(.*)"/U', $string, $result);

$foo = array_pop($result);