请考虑以下代码:
$imagePath = "https://s22.postimg.org/3k3o9ly8t/testigo.jpg";
$imagedata = get that image data through curl and store in this variable;
echo strlen($imagedata); // outputs 4699
if(strlen($imagedata) == 4699 ) {
echo "length is 4699";
}
即使 strlen 值为 4600,上面的 if 条件也永远不会成立。看起来很奇怪;我错过了什么吗?我已经尝试过了mb_strlen
,但没有用。
更新:它似乎适用于某些图像,但不适用于以下图像。
代码:
$strImageURL = "https://s22.postimg.org/3k3o9ly8t/testigo.jpg";
$strImageData = getData($strImageURL);
echo "<br />" . strlen($strImageData);
if(strlen($strImageData) === 4699) {
echo "true";
}
function getData($strSubmitURL)
{
$strData = null;
$ch = curl_init();
//return parameter
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 140);
//site name
curl_setopt($ch, CURLOPT_URL,$strSubmitURL);
// don' verify ssl host
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
$strData = curl_exec ($ch);
if (!$strData) {
//die ("cURL error: " . curl_error ($ch) . "\n");
return '';
}
curl_close ($ch);
unset($ch);
return $strData;
}