『壹』 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].'>';
}
這樣所得到的結果基本上就等於是你所想要的結果。