我已经使用以下代码替换HTML页面上的所有链接。使用PHP替换HTML页面正文中的所有链接使用PHP
$output = file_get_contents($turl);
$newOutput = str_replace('href="http', 'target="_parent" href="hhttp://localhost/e/site.php?turl=http', $output);
$newOutput = str_replace('href="www.', 'target="_parent" href="http://localhost/e/site.php?turl=www.', $newOutput);
$newOutput = str_replace('href="/', 'target="_parent" href="http://localhost/e/site.php?turl='.$turl.'/', $newOutput);
echo $newOutput;
我想修改这段代码,只替换正文中的链接而不是正文。
我看到你的评论,你需要保持头部。看看我更新的答案 – Andreas