以下是我目前正在使用的代码:
try {
// Use '' al default
if(isset($_GET['url'])) {
$url = $_GET['url'];
unset($_GET['url']);
} else {
$url = '';
}
$proxy = new Proxy();
echo $proxy->run($url, $_GET, $_POST);
} catch(Exception $e) {
echo 'Error: '.$e->getMessage();
}
这是我遇到问题的代码的一部分:
echo $proxy->run($url, $_GET, $_POST);
这将通过代理运行后回显网站。我尝试做的是用以下文字替换<head>
:<head> this is a test
所以,我尝试将代码更改为:
try {
// Use '' al default
if(isset($_GET['url'])) {
$url = $_GET['url'];
unset($_GET['url']);
} else {
$url = '';
}
$proxy = new Proxy();
$proxy_replace = str_replace('<head>','<head> this is a test',$proxy);
echo $proxy_replace->run($url, $_GET, $_POST);
} catch(Exception $e) {
echo 'Error: '.$e->getMessage();
}
但这是我得到的错误:
Catchable fatal error: Object of class Proxy could not be converted to string in /home/username/public_html/testfolder/index.php on line 249
非常感谢任何帮助......
答案 0 :(得分:4)
您需要在下载的HTML上执行替换,而不是在Proxy
实例上执行替换。这样的事情应该有效:
try {
// Use '' al default
if(isset($_GET['url'])) {
$url = $_GET['url'];
unset($_GET['url']);
} else {
$url = '';
}
$proxy = new Proxy();
$html = $proxy->run($url, $_GET, $_POST);
$html_replace = str_replace('<head>','<head> this is a test',$html);
echo $html_replace;
} catch(Exception $e) {
echo 'Error: '.$e->getMessage();
}