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

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

WBOY
WBOYOriginal
2016-06-13 12:13:471061browse

正则问题 将图片宽度替换为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>';


宽度替换为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>';

------解决思路----------------------
$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);


正则有关问题 将图片宽度替换为100%http://xxxx/uploads/details/142163431741415.jpg">正则有关问题 将图片宽度替换为100%http://xxxx/uploads/details/14216343172321.jpg">




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