我用下面的正则表达式得到IMG-代码网址:如何提取图像的src网址,省略“?”和查询字符串?
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post_single->post_content, $matches);
然而,$匹配给我下面的结果:
http://example.com/wp-content/uploads/2013/11/dsc_842.jpg
- >这是好的。
http://example.com/wp-content/uploads/2013/11/dsc_0546.jpg?w=640
- >这不好。
如何更改正则表达式以防止结果中包含?w=640
的情况?
非常感谢帮助。
谢谢!
''/
只要把我的两分钱:因为你使用Wordpress(在PHP),你可以使用函数[''parse_url()'](http://php.net/manual/en/function .parse的URL。PHP),它能够立即处理您的所有需求。 – Jan