开发者

Can I use a variable instead of a url in curl_setopt ($sh, CURLOPT_URL,

<?php

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, 'http://192.168.0.14:8081/home/');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$curl_response = curl_exec($ch);
curl_close($ch);

//Change link url

$link = $curl_response;

$linkgo = '/sickbeard_public';
$linkfind = 'href="';
$linkreplace = 'href="' . $linkgo ;

$link = str_replace($linkfind, $linkreplace, $link);


//Change js url
$js = $link;

$jsgo = 'http://192.168.0.14:8081';
$jsfind = 'src="';
$jsreplace = 'src="' . $jsgo ;

$js = str_replace($jsfind, $jsreplace, $js);


//Fix on page link errors
$alink = $js;
$alinkgo = 'http://192.168.0.14:8081/';
$alinkfind = 'a 开发者_Go百科href="/sickbeard_public/';
$alinkreplace = 'a href="' . $alinkgo ;

$alink = str_replace($alinkfind, $alinkreplace, $alink);
_________________

$sh = curl_init();
$url = $alink;
curl_setopt ($sh, CURLOPT_URL, $url);
curl_setopt ($sh, CURLOPT_RETURNTRANSFER, 1);
$curl_res = curl_exec($sh);


echo $curl_res;

?>

I'm trying to pull a webpage and then when links on that page are clicked I want the original urls to be curled. The code works up to the line if I have echo $alink; instead of the stuff after the line. But with the code showing above it doesn't. The curling of clicked urls doesn't work. Been fiddling with it for a few hours but google isn't helping and I have no idea what to do now. Please assist.. Thanks


make sure that all the variable values after "?" are "urlencode()", especially spaces otherwise it won't work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜