欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
php正則表達式,取img標記中任意屬性,正則替換去掉或改變圖片img標記中的任意屬性 -...
php正則表達式,取img標記中任意屬性,正則替換去掉或改變圖片img標記中的任意屬性
[ 時(shí)間:2009-08-06 09:59:17 | 瀏覽:1359 次 | 來(lái)源: | 作者: ]

本文word版下載:http://www.web126.com/upload/edit_pic/20090806101735.doc

本文txt版下載:http://www.web126.com/upload/edit_pic/20090806102141.txt

一次做新聞系統時(shí)因為要固定新聞頁(yè)圖片的大小并且要加鏈接,因此就去網(wǎng)上找,結果還真找到了,首頁(yè)把新頁(yè)實(shí)現代碼貼出來(lái):

$as_message = preg_replace(\'/<img.+src=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>/i\', "<a href=\"$1\" target=_blank title=點(diǎn)擊放大圖片><img src=\"$1\" border=0 onload=\"javascript:if(this.width>screen.width-600)this.width=screen.width-600\"  onmousewheel=\"return bbimg(this)\" ></a>", $as_message);
$as_message = preg_replace(\'/<IMG.+SRC=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>/i\', "<a href=\"$1\" target=_blank title=點(diǎn)擊放大圖片><img src=\"$1\" border=0 onload=\"javascript:if(this.width>screen.width-600)this.width=screen.width-600\"  onmousewheel=\"return bbimg(this)\" ></a>", $as_message);

另一種固定圖片的js方法:

<table width="90%" border="0" cellpadding="0" cellspacing="0" id="abc">
  <tr>
    <td> </td>
  </tr>
</table>
<script>
var abc=document.getElementById("abc");
var imgs=abc.getElementsByTagName("img");
for (var i=0,g;g=imgs[i];i++)
g.onload=function(){if (this.width>600){this.width=600}else{if (this.height>600)this.height=600}}
</script>

 

參考如下:

因有一項目新聞發(fā)布系統,數據庫內容字段中存儲的是原圖的路徑(當然還有其他文字內容啦,內容里插圖時(shí),存的是圖片路徑),但前臺想使用縮略圖,琢磨1小時(shí)余,得到以下結果,可解決問(wèn)題(取img標簽會(huì )了,取別的標簽任意屬性自然也會(huì )了):


<?php
/*正則取圖片img標記中的任意屬性*/
$word = \'<p height="22" align="cenetr">111 22</p> <img  height="60" src="/upload/images/aaa.jpg"    width=100 style=><div style="float:left;">中國人</div>\';
//取width
preg_match(\'/<img.+(width=\"?\d*\"?).+>/i\',$word,$matches);
echo $matches[1];

//取height
preg_match(\'/<img.+(height=\"?\d*\"?).+>/i\',$word,$matches);
echo $matches[1];

//取src
preg_match(\'/<img.+src=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>/i\',$word,$matches);
echo $matches[1];

/*正則替換去掉或改變圖片img標記中的任意屬性***************************************************************/
$str = \'<p height="22" align="cenetr">111 22</p> <img  height="60" src="/upload/images/aaa.jpg"    width=100 style=><div style="float:left;">中國人</div>
<p height="22" align="cenetr">31313 224344</p> <img src="/upload/images/bbb.jpg"  height="60"    width=100 style=><div style="float:left;">1212121</div>\';


//改變src屬性(此處將原來(lái)的src="/upload/images/bbb.jpg"改變?yōu)?/font>src="/upload/_thumbs/Images/bbb.jpg")
print preg_replace(\'/(<img.+src=\"?.+)(images\/)(.+\.(jpg|gif|bmp|bnp|png)\"?.+>)/i\',"\${1}_thumbs/Images/\${3}",$str);


/*改變src屬性,
此處將原來(lái)的src="/upload/images/bbb.jpg"改變?yōu)閟rc="/upload/_thumbs/Images/bbb.jpg",并舍棄寬和高
(比如你想在前臺顯示縮略圖,但數據庫中存儲的是原圖的路徑。為什么要舍棄寬高??你縮略圖啊!還是原圖的寬高,會(huì )怎樣???)
*/
print preg_replace(\'/(<img).+(src=\"?.+)images\/(.+\.(jpg|gif|bmp|bnp|png)\"?).+>/i\',"\${1} \${2}_thumbs/Images/\${3}>",$str);

?>

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久