PHP 提取圖片img標記中的任意屬性的簡單實例
<?php
/* PHP正則提取圖片img標記中的任意屬性 */
$str = '<center><img src="/uploads/images/20100516000.jpg" height="120" width="120"><br />PHP正則提取或更改圖片img標記中的任意屬性</center>';
//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];
//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);
?>
相關文章
Laravel5.4框架使用socialite實現(xiàn)github登錄的方法
這篇文章主要介紹了Laravel5.4框架使用socialite實現(xiàn)github登錄的方法,結合實例形式分析了Laravel相關下載、安裝、配置及github登陸、注冊、設置等相關操作技巧,需要的朋友可以參考下2019-03-03

laravel5.0在linux下解決.htaccess無效和去除index.php的問題

laravel 框架結合關聯(lián)查詢 when()用法分析