我使用的file_get_contents在我的網站 顯示其他網站,我想這裏面的內容全部鏈接是這樣的:更改所有鏈接的file_get_contents內PHP
<a href="www.google.com/about.us"></a>
不喜歡這樣的:
<a href="/about.us"></a>
我使用的file_get_contents在我的網站 顯示其他網站,我想這裏面的內容全部鏈接是這樣的:更改所有鏈接的file_get_contents內PHP
<a href="www.google.com/about.us"></a>
不喜歡這樣的:
<a href="/about.us"></a>
我會在輸出字符串上使用str_replace()
。例如,
$newOutput = str_replace('<a href="/', '<a href="www.google.com/', $output);
哪裏$output
是從file_get_contents()
數據。例如,
$output = file_get_contents('example.txt');
編輯:
爲了配合新的要求,您在評論中爲了做到這一點只在身體的聯繫,那麼你應該將$output
分成兩個部分提到,頭部和身體,然後只在第二個這樣做。因此,你應該有的代碼是:
$output = file_get_contents('example.txt'); //get all content
$outputArray = explode('</head>', $output); //split the content
$outputBody = $outputArray[1]; //get everything after the </head>
$newOutput = str_replace('<a href="/', '<a href="www.google.com/', $outputBody);
爲什麼你顯示其他人的網站?我曾經有人在我的網站上做過這件事,我真的很討厭它! – Jerodev
比什麼是問題? – MKR
我想在線代理 –