Home > Backend Development > PHP Tutorial > PHP正则如何匹配图片

PHP正则如何匹配图片

WBOY
Release: 2016-06-23 14:15:24
Original
1085 people have browsed it

preg_match('#PHP正则如何匹配图片"]+?([^"/]+?)"[^>]+>#is', 'PHP正则如何匹配图片', $matches); 
echo $matches[0];

这里匹配图片了, 但我想匹配图片里 alt="" 的图片 怎么匹配呢 


回复讨论(解决方案)

preg_match('/PHP正则如何匹配图片', $matches); 
echo $matches[0];

版主 好像匹配不了哦 。 输出空的

alt="" 改成 alt="(.+?)"试试看看

不行哦 。 而且要求的是 获取 alt="" 的 图片

版主 好像匹配不了哦 。 输出空的
不可能啊,我测试都没有问题

preg_match('/<img.+?src=["\'](.*?)["\'].*?alt=""/is', '<img src="http://127.0.0.1:81/upload/files/aaa.jpg" alt="" >', $matches); echo $matches[1];
Copy after login

测试没问题

<?phppreg_match('#<img .+?src="[^ alt="PHP正则如何匹配图片" >"]+?([^"/]+?)"[^>]*alt="([^"]*)"[^>]*>#is', '<img src="http://127.0.0.1:81/upload/files/aaa.jpg" alt="大幅度4" >', $matches); print_r($matches);
Copy after login

是不是alt出现在src前面了?

版主 是可以 。谢谢。。。 正则真头疼。。

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