我有一个Glype代理,我不想分析外部URL。网页上的所有网址都会自动转换为:http://proxy.com/browse.php?u=[URL HERE]。例如:如果我访问海盗湾在我代理的话,我想不解析以下网址:Preg-replace - 替换除域和其子域以外的所有URL
ByteLove.com (Not to: http://proxy.com/browse.php?u=http://bytelove.com&b=0)
BayFiles.com (Not to: http://proxy.com/browse.php?u=http://bayfiles.com&b=0)
BayIMG.com (Not to: http://proxy.com/browse.php?u=http://bayimg.com&b=0)
PasteBay.com (Not to: http://proxy.com/browse.php?u=http://pastebay.com&b=0)
Ipredator.com (Not to: http://proxy.com/browse.php?u=https://ipredator.se&b=0)
etc.
我当然想保持内部URL,因此:
thepiratebay.se/browse (To: http://proxy.com/browse.php?u=http://thepiratebay.se/browse&b=0)
thepiratebay.se/top (To: http://proxy.com/browse.php?u=http://thepiratebay.se/top&b=0)
thepiratebay.se/recent (To: http://proxy.com/browse.php?u=http://thepiratebay.se/recent&b=0)
etc.
有preg_replace替换除了thepiratebay.se之外的所有URL,还有子域名(如示例中所示)?另一个功能也是受欢迎的。 (如DOM文档,QueryPath中,SUBSTR或strpos不str_replace函数,因为那时我应该定义的所有URL)。
我找到了一些东西,但我不熟悉的preg_replace:
$exclude = '.thepiratebay.se';
$pattern = '(https?\:\/\/.*?\..*?)(?=\s|$)';
$message= preg_replace("~(($exclude)?($pattern))~i", '$2<a href="$4" target="_blank">$5</a>$6', $message);
它不工作,这是我的代码:http://pastebin.com/6ML8q7JN URL的位于:$ document – 2012-03-03 18:03:09
我需要查看$ document变量的内容以评估鳕鱼是否可以工作。 – 2012-03-03 18:11:42
它现在正在工作,但_&b = 0_在url后面。如何解决这个问题? – 2012-03-04 15:55:41