简体   繁体   中英

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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM