问题描述
我有一个像这样的字符串:
I have a string like this:
我应该使用什么PHP函数转换’
到实际的普通字符'
:
What PHP function should I use to convert the ’
to the actual "normal" char '
:
我正在使用CURL来获取页面,并且该页面中包含该字符串,但是由于某种原因
I'm using CURL to fetch a page and this page has that string in it but for some reason the HTML chars are not decoded.
my_url
测试页是一个带有iso字符的意大利语博客,所有
The my_url
test page is an Italian blog with iso characters, and all the apostrophes are encoded in html code like above.
$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.net手册开始:html_entity_decode()与htmlentities()相反,它可以将字符串中的所有HTML实体转换为它们的适用字符。
html_entity_decode. From the php.net manual: html_entity_decode() is the opposite of htmlentities() in that it converts all HTML entities in the string to their applicable characters.
这篇关于PHP函数将HTML代码转换为普通字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!