【发布时间】:2012-02-13 04:14:40
【问题描述】:
我有一个这样的字符串:
La Torre Eiffel paragonata all’Everest
我应该使用什么 PHP 函数将 ’ 转换为实际的“普通”字符 ':
La Torre Eiffel paragonata all'Everest
我正在使用 CURL 来获取一个页面,并且该页面中包含该字符串,但由于某种原因,HTML 字符没有被解码。
my_url 测试页面是一个带有 iso 字符的意大利博客,所有的撇号都是用上面的 html 代码编码的。
$output = curl_download($my_url);
$output = htmlspecialchars_decode($output);
function curl_download($Url){
// is cURL installed yet?
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
// OK cool - then let's create a new cURL resource handle
$ch = curl_init();
// Now set some options (most are optional)
// Set URL to download
curl_setopt($ch, CURLOPT_URL, $Url);
// Set a referer
curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
// User agent
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
return $output;
}
【问题讨论】:
标签: php curl decode html-entities