Php 如果URL包含特殊特许,CURL不会返回任何内容
我想使用CURL从url获取详细信息,它对普通字符url很有效。但其中一个URL包含特殊字符,如“ó” 我的URL示例如下:Php 如果URL包含特殊特许,CURL不会返回任何内容,php,curl,Php,Curl,我想使用CURL从url获取详细信息,它对普通字符url很有效。但其中一个URL包含特殊字符,如“ó” 我的URL示例如下: http://www.abc.com/aóvek-xyz-pqr/1/8/ 我的php代码是: $ch = curl_init($my_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); $content = c
http://www.abc.com/aóvek-xyz-pqr/1/8/
我的php代码是:
$ch = curl_init($my_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$content = curl_exec($ch);
请尝试以下内容(摘自):
http中的URL只能用一组特定的字符构造。对于每一个,你需要对它们进行百分比编码 在PHP中,可以使用urlencode 您的代码应该如下所示
$ch = curl_init(urlencode($my_url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$content = curl_exec($ch);
试试这个
function get_web_page( $url )
{
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
curl_close( $ch );
return $content;
}
echo get_web_page("http://en.wikipedia.org/wiki/ó");
函数获取网页($url)
{
$options=array(
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_头=>false,
CURLOPT_FOLLOWLOCATION=>true,
);
$ch=curl\u init($url);
curl_setopt_数组($ch$options);
$content=curl\u exec($ch);
卷曲关闭($ch);
返回$content;
}
回显获取网页(“http://en.wikipedia.org/wiki/ó");
对$my_url使用urlencode。另外:这个url不存在,你能提供一个这样的工作url吗?所以我们可以测试一下?@Паааааааааааааа1072 function get_web_page( $url ) { $options = array( CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, ); $ch = curl_init( $url ); curl_setopt_array( $ch, $options ); $content = curl_exec( $ch ); curl_close( $ch ); return $content; } echo get_web_page("http://en.wikipedia.org/wiki/ó");