亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長(zhǎng)資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    php如何替換圖片地址

    php替換圖片地址的方法:可以通過(guò)正則表達(dá)式實(shí)現(xiàn)替換,使用方法如:【preg_match('/<s*imgs+[^>]*?srcs*=s*('|")(.*?)\1[^>]*?/?s*>/i',$str,$match);】。

    php如何替換圖片地址

    preg_match 函數(shù)用于執(zhí)行一個(gè)正則表達(dá)式匹配。

    (推薦教程:php圖文教程)

    函數(shù)語(yǔ)法:

    int preg_match (string $pattern, string $subject[, array &$matches[, int $flags = 0[, int $offset = 0 ]]])

    返回 pattern 的匹配次數(shù)。 它的值將是 0 次(不匹配)或 1 次,因?yàn)?preg_match() 在第一次匹配后 將會(huì)停止搜索。

    (學(xué)習(xí)視頻推薦:php視頻教程)

    代碼實(shí)現(xiàn):

    <?php  /*PHP正則提取圖片img標(biāo)記中的任意屬性*/ $str = '<center><img src="/uploads/images/20100516000.jpg" height="120" width="120"><br />PHP正則提取或更改圖片img標(biāo)記中的任意屬性</center>';  //1、取整個(gè)圖片代碼 preg_match('/<s*imgs+[^>]*?srcs*=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標(biāo)記中的任意屬性*/ //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);  ?>

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)