當前位置:首頁 » 編程語言 » php匹配src

php匹配src

發布時間: 2023-01-15 01:52:44

Ⅰ 正則匹配一個文本中的所有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>

熱點內容
java深入學習 發布:2025-07-15 10:13:50 瀏覽:533
linux應用程序開發pdf 發布:2025-07-15 10:11:37 瀏覽:911
解壓冷知識 發布:2025-07-15 10:11:35 瀏覽:78
outlook郵件的伺服器是什麼 發布:2025-07-15 09:45:59 瀏覽:482
如何安排資產配置 發布:2025-07-15 09:33:24 瀏覽:906
更新傳送伺服器目的地址失敗 發布:2025-07-15 09:27:05 瀏覽:484
c語言else的用法 發布:2025-07-15 09:19:54 瀏覽:119
tnt蘋果核安卓怎麼加好友 發布:2025-07-15 09:05:15 瀏覽:239
年輕人運行內存為什麼比安卓好 發布:2025-07-15 08:52:03 瀏覽:515
怎麼配置組策略 發布:2025-07-15 08:52:02 瀏覽:246