Php 如何解决卷曲此页时无法识别的字符

Php 如何解决卷曲此页时无法识别的字符,php,curl,Php,Curl,我的代码在这里,问题与我的另一个问题不同,这里我遇到的问题是在我成功地卷起页面之后,但是我看到的所有字符都是无法识别的,例如。“��Ƶ�̳̣�2012�棩", 如何使它们正常出现 $cookie_file = tempnam('./temp','cookie'); $login_url = 'http://bbs.php100.com/login.php'; $post_fields = 'cktime=3600&step=2&pwuser=username&pwpwd=

我的代码在这里,问题与我的另一个问题不同,这里我遇到的问题是在我成功地卷起页面之后,但是我看到的所有字符都是无法识别的,例如。“��Ƶ�̳̣�2012�棩", 如何使它们正常出现

$cookie_file = tempnam('./temp','cookie');
$login_url = 'http://bbs.php100.com/login.php';
$post_fields = 'cktime=3600&step=2&pwuser=username&pwpwd=password';

$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_exec($ch);
curl_close($ch);

$url = 'http://bbs.php100.com/index.php';//or specific page
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);

//preg_match("",$contents,$arr);
//echo $arr[1];

curl_close($ch);

您需要将页面内容保存为变量并转换编码

$url = 'http://bbs.php100.com/index.php';//or specific page
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
// Note "1"! It is needed for curl_exec() to return contents of the page
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
$contents = iconv('gbk','utf8',$contents);
echo $contents;

如果您使用的不是
UTF-8
编码,请根据需要设置
iconv
的第二个参数。

您需要将页面内容保存为变量并转换编码

$url = 'http://bbs.php100.com/index.php';//or specific page
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
// Note "1"! It is needed for curl_exec() to return contents of the page
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
$contents = iconv('gbk','utf8',$contents);
echo $contents;

如果您使用的不是
UTF-8
编码,请根据需要设置
iconv
的第二个参数。

您如何“看到”这些字符?您是否将它们回显到命令行或显示在页面上?您如何在输出前修改文本?这些是我的全部代码,我在web浏览器(firefox)中看到这些字符。您如何“看到”“这个角色?您是将它们回显到命令行还是显示在页面上?在输出之前如何修改文本?这些是我的全部代码,我在网络浏览器(firefox)中看到了这些字符。