我使用的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
我想在线代理 –