【发布时间】:2013-07-25 08:13:03
【问题描述】:
我总是遇到正则表达式的问题,我基本上有一个url,例如:
http://somedomain.com/something_here/bla/bla/bla/bla.jpg
我需要一个 preg_replace() 来用空字符串替换 something_here,并保留其他所有内容。
我尝试了以下方法,它替换了错误的部分:
$image[0] = preg_replace('/http:\/\/(.*)\/(.*)\/wp-content\/uploads\/(.*)/','$2' . '',$image[0]);
这最终只留下了我想要替换的部分,而不是实际替换它!
【问题讨论】:
-
为此使用
parse_url()并在路径部分进行替换。
标签: php regex replace preg-replace