Home > Backend Development > PHP Tutorial > 正则有关问题 将图片宽度替换为100%

正则有关问题 将图片宽度替换为100%

WBOY
Release: 2016-06-13 12:13:47
Original
1060 people have browsed it

正则问题 将图片宽度替换为100%
宽度不定的图片

$str = '<p><br></p><img    style="max-width:90%" src="<br / alt="正则有关问题 将图片宽度替换为100%" >http://xxxx/uploads/details/142163431741415.jpg"><img    style="max-width:90%" src="<br / alt="正则有关问题 将图片宽度替换为100%" >http://xxxx/uploads/details/14216343172321.jpg"><p><br></p>';
Copy after login
Copy after login


宽度替换为100%

$str = '<p><br></p><img    style="max-width:90%" src="<br / alt="正则有关问题 将图片宽度替换为100%" >http://xxxx/uploads/details/142163431741415.jpg"><img    style="max-width:90%" src="<br / alt="正则有关问题 将图片宽度替换为100%" >http://xxxx/uploads/details/14216343172321.jpg"><p><br></p>';
Copy after login
Copy after login

------解决思路----------------------
$str = '<p><br></p><img    style="max-width:90%" src="<br / alt="正则有关问题 将图片宽度替换为100%" >http://xxxx/uploads/details/142163431741415.jpg"><img    style="max-width:90%" src="<br / alt="正则有关问题 将图片宽度替换为100%" >http://xxxx/uploads/details/14216343172321.jpg"><p><br></p>';

echo preg_replace('/(?<=style="width:).+?px;/i', '100%', $str);
Copy after login


http://xxxx/uploads/details/142163431741415.jpg">http://xxxx/uploads/details/14216343172321.jpg">




------解决思路----------------------
这样呢
echo  preg_replace('/(?<=正则有关问题 将图片宽度替换为100%

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template