【发布时间】:2012-07-31 03:51:36
【问题描述】:
我正在使用以下 preg_replace() 调用来用新结构替换链接:
preg_replace('/example.com\/sub-dir\/(.*)">/', 'newsite.co.uk/sub-dir/$1.html">', $links);
它几乎可以工作,除了它没有将“.html”添加到替换的末尾,所以它最终像“newsite.co.uk/sub-dir/page-identifier”而不是“newsite.co.uk/sub-dir/page-identifier.html”。
我确信我错过了一些简单的事情,但是谷歌搜索问题并没有得出任何有用的结果,所以我希望这里有人可以提供帮助!
提前致谢!
编辑:例如,这里是 $links 的链接端
<a href="http://example.com/sub-dir/the-identifier">Anchor</a>
如果我将正则表达式更改为 (.*?) 则上述示例有效,但以下示例无效:
<a class="prodCatThumb" title="View product" href="http://example.com/sub-dir/product-identifier">
结果是
<a class="prodCatThumb.html" title="View product" href="http://example.com/sub-dir/product-identifier">
有什么想法吗?
【问题讨论】:
-
你能告诉我们
$links的内容吗? -
@Ashley:请看我的编辑,因为我已经为你解决了这个问题
标签: php preg-replace