我已經使用以下代碼替換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