php匹配src
Ⅰ 正则匹配一个文本中的所有src
$reg="/src[=\"\'\s]+([^\"\']+)[\"\']/i";
$str="";
if(preg_match_all($reg,$str,$m)){
for($i=0;$i<count ( $m [1] );$i++){
echo $m[1][$i];
}
}
Ⅱ php正则匹配和替换IMG标签问题
不知道这个是否符号你的要求:
<?php
$string = '<img src="abc"/><img src="efg"/><link src="a.css"/>';
echo preg_replace('/<img(.*?)src=/i','<img$1Layzyload=',$string);
//End_php
//输出
<img Layzyload="abc"/><img Layzyload="efg"/><link src="a.css"/>
Ⅲ PHP正则表达式如何匹配iframe中的src属性
$str = '<IFRAME marginWidth=0 marginHeight=0 src="/play.php?id=136498" frameBorder=0 width=310 scrolling=no height=240 scrollbars="yes,resizable=yes" menubar="no,location=no,"></IFRAME>';preg_match ("/src=\"(.*)\"/", $str, $match);$src = $match[1];
Ⅳ php 正则怎样匹配img标签的src内容
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><?php
//代码直接运行即可
$str='eeeeeee<imgsrc="aaaa.jpg"/>asad';
preg_match('/<imgsrc="(.*?)"//',$str,$result);
print_r($result['1']);
die();
?>
Ⅳ php如何使用正则表达式匹配url图片啊
可以这样:
$image="http://xxxxxxxxx.jpg"
preg_match("/(http://)?w+.jpg/",$image,$matches);//http://可要可不要
echo$matches[0];//$matches[0]即为匹配的图片路径
以上只是匹配jpg类型的图片
如果要匹配其他类型可以这样使用
preg_match("/(http://)?w+.(jpg|jpeg|gif|png)/",$image,$matches);
echo$matches[0];
Ⅵ php 正则表达式怎么把图片URL匹配出来呢
使用preg_match_all函数,即可实现你的要求。代码如下:
$str='<imgdatasrc="http://mm..com/mmbiz/2ItUdTx3iamOFK8QVqofnQ/640?tp=webp"data-s="300,640"data-ratio="0.625"data-w="400"style="box-sizing:border-box!important;width:auto!important;word-wrap:break-word!important;visibility:visible!important;"/>';
$pattern='/<img.*src="(.*?)"/';
preg_match_all($pattern,$str,$matches);
echo$matches[1][0];
//返回:http://mm..com/mmbiz/2ItUdTx3iamOFK8QVqofnQ/640?tp=webp
Ⅶ php怎么获取图片的src
$str=<<<CODE
<imgwidth="100"id="ab_0"name="ab_0"height="80"src="images/ab.jpg"/>
CODE;
preg_match('/(?<=src="images/)[a-z.]+/i',$str,$arr);
print_r($arr);
Ⅷ php正则匹配怎么写
首先,这段代码是没有问题的。
你那里匹配不到可能是因为你的$a并不是你提供的这一段,而是其他的带有换行的字符串。
解决换行的方法是使用模式修正符s,得到:
preg_match("/<asrc.*?>/s",$a,$arr);
另外,看情况,可以追加一个模式修正符i,不区分大小写。
Ⅸ php匹配<img/>,添加width,height
这个问题你想复杂了,其实直接在前台用CSS样式控制就可以了。
比如你的通过编辑器编辑的内容最终在一个类样式为.content的DIV中显示,则添加样式
.content img{width:100px;height:100px;border:0px;}
就可以控制这个DIV下所有的图像了,没必要去程序中处理。
或者通过JS控制也是可行的方法.
假设显示这些图片的DIV容器的ID是content
<div id="content"></div>
<script language="javascript">
function DrawImage(ImgD,w,h){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
if(image.width/image.height>1){
if(image.width>w){
ImgD.width=w;
ImgD.height=(image.height*w)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else{
if(image.height>h){
ImgD.height=h;
ImgD.width=(image.width*h)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
}
var images =document.getElementById("content").getElementsByTagName("img");
for(var i=0;i<images.length;i++){
var img =images[i];
DrawImage(img,100,100);
}
</script>