php – 额外值1附加卷曲响应

前端之家收集整理的这篇文章主要介绍了php – 额外值1附加卷曲响应前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
从以下两个文件我得到输出(2000)1但它应该只(2000)

使用curl获得价值后,附加1会附加,但为什么呢?

balance.PHP

<?PHP
$url = "http://localhost/sms/app/user_balance.PHP";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,2);
curl_setopt($ch,CURLOPT_POSTFIELDS,"id=2&status=Y");
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>

user_balance.PHP

<?PHP
$conn = MysqL_connect("localhost","root","");
MysqL_select_db("sms",$conn);
$user_id = $_REQUEST["id"];
$sql = "SELECT * FROM user_sms WHERE user_id='$user_id'";
$rec = MysqL_query($sql);
if($row = MysqL_fetch_array($rec)) {
    $balance = $row["user_sms_balance"];
}
echo "(".$balance.")";
?>
curl_setopt()PHP手册文档:

CURLOPT_RETURNTRANSFER – Set value to TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.

如果不设置CURLOPT_RETURNTRANSFER选项设置为TRUE,然后从curl_exec()的返回值将是操作的布尔值 – 1或0.为了避免它,你可以设置CURLOPT_RETURNTRANSFER为TRUE,如下图所示:

curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

猜你在找的PHP相关文章