简体   繁体   English

我可以在curl_setopt($ sh,CURLOPT_URL,

[英]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. 我正在尝试拉一个网页,然后单击该页面上的链接时,我希望将原始URL卷曲。 The code works up to the line if I have echo $alink; 如果我有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. 是“ urlencode()”,尤其是空格,否则它将不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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