当我使用cURL获取网站并对结果执行strlen()时,我得到72354.但是当我通过htmlspecialchars()传递结果然后执行strlen()时,我得到0.任何想法?这是我的代码:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/search?q=test');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);
echo strlen($result);
echo '<br>';
echo strlen(htmlspecialchars($result));
答案 0 :(得分:2)
试
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/search?q=test');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);
echo strlen($result);
echo '<br>';
echo strlen(htmlspecialchars($result, ENT_QUOTES));
echo '<br>';
echo htmlspecialchars($result, ENT_COMPAT,'ISO-8859-1', true);
?>