0
我想下载一个站点,将该站点上的所有链接替换为内部链接。正则表达式替换所有链接,但css和js
,很容易:
$page=file_get_contents($url);
$local=$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$page=preg_replace('/href="(.+?)"/','href="http://'.$local.'?href=\\1"',$page);
,但我想排除更换所有css文件和js文件,所以我尝试:
$regex='/href="(.+?(?!(\.js|\.css)))"/';
$page=preg_replace($regex,'href="http://'.$local.'?href=\\1"',$page);
,但没有工作,
什么时我做错了?
我想
?!
是负先行
THX,该正则表达式工作 – rubo77