PREG_MATCH问题
preg_match("/<img onClick='this\.style\.maxWidth=\"490px\"; this\.style\.maxHeight=\"490px\";
this\.style\.cursor=\"default\";' style='cursor: pointer; display: block; float: left; max-width:
490px; max-height: 160px;' src='(.)+'><br style='clear: left;'>/",$CONTENT,$MATCHES);
print_r($MATCHES);
为什么没有获取到图片源呢?
preg_match("/<img onClick='this\.style\.maxWidth=\"490px\"; this\.style\.maxHeight=\"490px\";
this\.style\.cursor=\"default\";' style='cursor: pointer; display: block; float: left; max-width:
490px; max-height: 160px;' src='(.)+'><br style='clear: left;'>/",$CONTENT,$MATCHES);
print_r($MATCHES);
Why doesn't this get the image source?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
考虑编写
src='(.+)'
而不是src='(.)+'
Consider writing
src='(.+)'
instead ofsrc='(.)+'
您可以跳过很多内容,只需说
$matches[1]
将是 src url(在评论失控之前:这是基于问题中的原始模式。它确实不匹配双引号属性,因为原始模式也不匹配,而且它也不是一个通用的解决方案,它会寻找 1 个格式良好的 img 标签,仅此而已)
除此之外:
单引号围绕属性?!哎呀!那个是错的!抱歉,这些都不好!
You can skip a lot of that stuff and just say
$matches[1]
will be the src url(Before the comments get out of hand: This is based on the original pattern in the question. it doens't match double-quoted attributes, because the original pattern didn't either. And it's not a general solution either. It'll look for 1 well-formed img tag, and that's it)
Other than that:
Single quotes around attributes?!whoops! Wrong about that one! ApologiesNone of that is good!