搜尋
首頁php教程PHP源码php正则取img标记中alt src width heigh属性

<script>ec(2);</script>

/*正则取图片img标记中的任意属性*/

$word = '

111 22

php正则取img标记中alt src width heigh属性
中国人
';
//取整个图片代码
preg_match('/php正则取img标记中alt src width heigh属性/is',$word,$matches);
echo $matches[0];//结果:php正则取img标记中alt src width heigh属性


$word = '

111 22

php正则取img标记中alt src width heigh属性
中国人
';
//取width
preg_match('/php正则取img标记中alt src width heigh属性/i',$word,$matches);
echo $matches[1];

//取height
preg_match('/php正则取img标记中alt src width heigh属性/i',$word,$matches);
echo $matches[1];

//取src
preg_match('/php正则取img标记中alt src width heigh属性/i',$word,$matches);
echo $matches[1];

/*正则替换去掉或改变图片img标记中的任意属性***************************************************************/
$str = '

111 22

php正则取img标记中alt src width heigh属性
中国人

31313 224344

php正则取img标记中alt src width heigh属性
1212121
';


//改变src属性(此处将原来的src="/upload/images/bbb.jpg"改变为src="/upload/_thumbs/Images/bbb.jpg")
print preg_replace('/(php正则取img标记中alt src width heigh属性)/i',"${1}_thumbs/Images/${3}",$str);


/*改变src属性,
此处将原来的src="/upload/images/bbb.jpg"改变为src="/upload/_thumbs/Images/bbb.jpg",并舍弃宽和高
(比如你想在前台显示缩略图,但数据库教程中存储的是原图的路径。为什么要舍弃宽高??你缩略图啊!还是原图的宽高,会怎样???)
*/
print preg_replace('/(php正则取img标记中alt src width heigh属性/i',"${1} ${2}_thumbs/Images/${3}>",$str);

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 個月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
1 個月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
1 個月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它們
1 個月前By尊渡假赌尊渡假赌尊渡假赌

熱工具

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)