當前位置:首頁 » 編程語言 » phpsrc

phpsrc

發布時間: 2023-05-29 20:07:35

php中要插入圖片時,src後面如何使用變數如題 謝謝了

這樣<img src="<?php echo $name_str ;?>"扮蘆width="1644" height="1046"> 如果本身已經在PHP語句雀遲中 那就這樣頃缺李<img src="{$name_str }"width="1644" height="1046">

② php 正則替換src裡面的內容

<?php

$str='imgsrc="abcccccccccc"';

$str=preg_replace('/src=".*?"/','src="helloworld"',$str);

echo$str;

③ 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];

④ 正則表達式取src部分 php

<?php

$body='<imgsrc="
http://www.honey58.com/uploads/allimg/201506/fo169841gsc4bgzr1h.jpg">缺瞎陸'
;

preg_match_all('/<img[^>]*src=['"神態]http://[^/]*([^'"]*)['"][^>]*>/is',$body,伏頃$img_array);

print_r($img_array);

⑤ PHP匹配圖片地址SRC的正則

不用循環,PHP提供一個preg_match_all函數的。

preg_match_all("/<img.*?src=[\\\'| \\\"](.*?(?:[\.gif|\.jpg]))[\\\'|\\\"].*?[\/]?>/",$content_2,$getPicPath); //正則獲取文章中的<img>標簽

上面就是我曾經用過的獲取圖片的正則。希望能幫到你

⑥ 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 正則查找 圖片的src 並替換相應的src

/TestDemo/Tpl/default/Public/Files/2010_09_04/1283591048.jpg轉
/TestDemo/Tpl/default/File/Uploads/2010_9_6/1283591048.jpg
根據你題目裡面舉例的這種對比的需求,轉換條件認為是
「/Public/Files/全日期/數字.jpg」形式的圖片轉換成
「/File/Uploads/緊縮日期/數字.jpg」形式的圖片。如果實際你的需求有所不同,可以根據這個略微對正則做修改。代碼替換部分如下:

$str1 = "<p><img height=\"32\" alt=\"\" src=\"/TestDemo/Tpl/default/Public/Files/2010_09_04/1283591048.jpg\" width=\"32\" border=\"0\" />來留言看看這的風景好嗎 <img alt=\"\" src=\"/TestDemo/Public/kindeditor/plugins/emoticons/13.gif\" border=\"0\" /></p><img height=\"32\" alt=\"\" src=\"/TestDemo/Tpl/default/Public/Files/2010_12_01/88668866.jpg\" width=\"32\" border=\"0\" />";
//這里多舉一個圖片例子試試
$str2 = preg_replace("/(src=\"[^\"]*?)\/Public\/Files(\/\d{4}_)[0]?(\d{1,2}_)[0]?(\d{1,2}\/\d+[.](?:jpg|gif|bmp)\")/","$1/File/Uploads$2$3$4$5",$str1);
?>
//規則有不同的話你可以這里對比修改下正則參數。good luck~

//----------------------------------------
既然需求少了那麼多,就可以
$str2 = preg_replace("/(src=\"[^\"]*?)\/Public\/Files(\/\d{4}_\d{1,2}_\d{1,2}\/\d+[.](?:jpg|gif|bmp)\")/","$1/File/Uploads$2",$str1);
行了,如果對圖片的格式限制不嚴格(嚴格點的就需要在尾巴那裡羅列出來),可以再簡化成
$str2 = preg_replace("/(src=\"[^\"]*?)\/Public\/Files(\/\d{4}_\d{1,2}_\d{1,2}\/\d+[.][a-zA-Z]+\")/","$1/File/Uploads$2",$str1);

⑧ 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 如何取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

熱點內容
我的世界電腦版伺服器怎麼禁足 發布:2024-04-23 13:24:49 瀏覽:546
y壓縮包 發布:2024-04-23 12:41:20 瀏覽:166
內網互相訪問 發布:2024-04-23 12:36:23 瀏覽:319
安卓國際服在哪裡看賬號 發布:2024-04-23 12:30:29 瀏覽:299
android開發伺服器 發布:2024-04-23 12:24:42 瀏覽:237
騰訊雲個人伺服器 發布:2024-04-23 12:24:40 瀏覽:803
debian下載源碼 發布:2024-04-23 12:20:43 瀏覽:479
curl本地IP伺服器 發布:2024-04-23 12:19:22 瀏覽:509
遺傳演算法神經網路matlab 發布:2024-04-23 11:57:43 瀏覽:722
安卓手機賣什麼 發布:2024-04-23 11:52:50 瀏覽:998