‘壹’ phpquery如何获取img的src值
pq(".show-content:eq(0) img:eq(0)")->attr('data-original-src')
phpquery是模拟jquery写的,attr才是jquery的方法, getAttribute是DOM的原生方法,不是jquery的方法。
‘贰’ php获取html标签image的src内容 正则表达式
php获取html标签image的src内容 正则表达式写法如下:
$str = '<img width="100" src="1.gif" height="100">';
preg_match_all('/<img.*?src="(.*?)".*?>/is',$str,$array);
print_r($array);
php对图片的操作正则表达式详解:
//1、取整个图片代码
preg_match('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i',$str,$match);
echo $match[0];
//2、取width
preg_match('/<img.+(width=\"?\d*\"?).+>/i',$str,$match);
echo $match[1];
//3、取height
preg_match('/<img.+(height=\"?\d*\"?).+>/i',$str,$match);
echo $match[1];
//4、取src
preg_match('/<img.+src=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>/i',$str,$match);
echo $match[1];
/*PHP正则替换图片img标记中的任意属性*/
//1、将src="/uploads/images/20100516000.jpg"替换为src="/uploads/uc/images/20100516000.jpg")
print preg_replace('/(<img.+src=\"?.+)(images\/)(.+\.(jpg|gif|bmp|bnp|png)\"?.+>)/i',"\${1}uc/images/\${3}",$str);
echo "<hr/>";
//2、将src="/uploads/images/20100516000.jpg"替换为src="/uploads/uc/images/20100516000.jpg",并省去宽和高
print preg_replace('/(<img).+(src=\"?.+)images\/(.+\.(jpg|gif|bmp|bnp|png)\"?).+>/i',"\${1} \${2}uc/images/\${3}>",$str);
?>
‘叁’ 我想知道PHP中获取HTML页面元素的img标签的src属性是怎么获取的
$img='<p><imgborder="0"alt=""src="/joke/images/joke/2015-09-09_870/20150909103535486.jpg"width="260"height="293">';
$result=preg_replace("/.*<img[^>]*src[=s"']+([^"']*)["'].*/","$1",$img);
echo$result." ";
‘肆’ PHP字符串提取一段文字中的img代码
<?php
$str='“欢迎查看美女图片<img src="images/new/h1.jpg" width="450" height="210" />哈哈!<img src="images/new/h1.jpg" width="450" height="210" />”';
echo $str;
preg_match_all('/<img.*\/>/iUs', $str, $out);
print_r($out);
$img=$out[0][0];
echo $img;
?>
运行这段代码,看看是不是你想要的~
‘伍’ php 正则匹配 获取img的src,过滤后显示统一的格式
我能给你提供的思路是做四遍替换。(比想正则表达式用的时间短)
首先备份原版后:
第一遍,你先把所有 ' 替换为 "。这样是为了统一格式,不会影响标签里的其他属性。
第二遍,用查找并替换 src= 为 src="。
第三遍,用查找并替换 .pn 为 .pn"。
这样所有src就是 ""url"" 和 "url" 两种状况了。
第四遍,将所有 "" 替换为 " 。
‘陆’ php 如何取img属性值 src
<?php
$pattern='<img.*?src="(.*?)">';
$html='<imgid="pic"name="pic"src="aaa.jpg"style="width:640px;">';
preg_match($pattern,$html,$matches);
echo$matches[1];
?>
我是参考别人的代码写的,你也可以看看http://..com/question/560630194.html
‘柒’ php 怎么输出img的src
PHP正则方式提取图片src属性
$ss = '<img src="/uploads/images/20150516000.jpg" height="120" width="120"><br />PHP正则提取SRC属性';
preg_match('/<img.+src=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>/i',$ss,$match); echo $match[1];
‘捌’ 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);
‘玖’ html中有三个img,鼠标选取一个,js使得class变成current,然后提交,php中如何取到这个img的src
Html代码
<input type='text' name='imgurl' id='imgurl'> //这里设置type='text'为了测试;如果测试没有问题,请把type='text' 改成type='hidden'
<img src='1.jpg' onclick='onCurrent(this);'>
<img src='2.jpg' onclick='onCurrent(this);'>
<img src='3.jpg' onclick='onCurrent(this);'>
js代码
var preObj = null; //保存上一次选中的图片的对象;
function onCurrent(obj){
if( preObj != null ){
preObj.className = ''; //如果上一次有选中图片,将class置于空
}
obj.className = 'current'; //选中图片class为current;
preObj = obj;
document.getElementById('imgurl').value = obj.crc; //把选中图片的路径放在input中,方便提交
}
php部分
$imgurl = $_POST['imgrul'];
这一段是最简单,也是最经典的做法
代码未测试,有问题可补充;
希望可以帮到你
‘拾’ php 正则匹配 获取img的src,过滤后显示统一的格式
没人回来,可能就是替换上比较难达成,主要是这匹配非字符串不行。
那换个思路,<img ....> 这个格式是固定的,可以忽略,那么重要的是src及等号后的这串字符。那么就有方法了。
$a='要匹配的字符串'
//$b即用来存储搜索的结果。
preg_match_all('/src=[^s>]*/',$a,$b);
for($i=0;$i<count($b[0]);$i++){
echo'<img'.$b[0][$i].'>';
}
这样所得到的结果基本上就等于是你所想要的结果。