【发布时间】:2015-03-19 22:01:51
【问题描述】:
Ebay 链接应替换为附属 ID。因此我使用 preg 替换。它在 $message 字符串中只有 1 个 URL 时有效。当 $message 字符串中有超过 1 个 URL 时,只有第一个 URL 有效。其他 URL 不会被替换。
$message = preg_replace('/<a(.*)href="(http:\/\/(cgi|www).ebay.*(=|\/)([0-9]{12,})[=\?\/]?[^"]*)"[^<]*<\/a>/Uis', '<a onclick="window.open(this.href); return false;" href="http://rover.ebay.com/rover/1/707-53477-19255-0/1?ff3=4&pub=3454345446&toolid=10001&campid=234342343&customid=&mpre=$2" title="Ebay Article: $5" target="_blank">http://www.ebay.com/itm/$5</a><img style="text-decoration:none;border:0;padding:0;margin:0;" src="http://rover.ebay.com/roverimp/1/707-53477-19255-0/1?ff3=4&pub=3454345446&toolid=10043&campid=345445454&customid=&mpt=[CACHEBUSTER]">', $message);
我发现,当我改变了
{12,}
到
{0,}
所有的 URL 都被替换了,但是 $5 是空的。但我在 URL 中需要这 5 美元。
有人有想法吗?
谢谢你
【问题讨论】:
标签: php regex html-parsing preg-replace