当前位置:网站首页>How PHP extracts image addresses from strings

How PHP extracts image addresses from strings

2022-06-25 11:19:00 Liu Yang's dream making program development station

Sometimes we have a need to extract the picture address in the product details and make it into an array , So that mall users can download pictures with one click ,PHP Extract the picture address in the string , In fact, it uses regular expressions to match image addresses , Let's look directly at the code

<?php
$str='<p><img border="0" src="upfiles/2009/07/1246430143_1.jpg" alt=""/></p>';// Product details page code
$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
preg_match_all($pattern,$str,$match);
print_r($match);//$match[0] For the extracted picture , Can be used directly ,$match[1] Is the extracted picture address , Need to write img Labeled src in
?>

原网站

版权声明
本文为[Liu Yang's dream making program development station]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206251100309269.html