这就是我现在所拥有的
将RSS源绘制到php中,来自rss feed的原始xml读取:
Paul’s Confidence
Run Code Online (Sandbox Code Playgroud)
我到目前为止的PHP就是这个.
$newtitle = $item->title;
$newtitle = utf8_decode($newtitle);
Run Code Online (Sandbox Code Playgroud)
以上回报;
Paul?s Confidence
Run Code Online (Sandbox Code Playgroud)
如果我删除utf_decode,我得到这个
Paul’s Confidence
Run Code Online (Sandbox Code Playgroud)
当我尝试str_replace;
$newtitle = str_replace("”", "", $newtitle);
Run Code Online (Sandbox Code Playgroud)
它不起作用,我得到;
Paul’s Confidence
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
Dav*_*d D 21
无论编码如何,这都是我的功能:
function RemoveBS($Str) {
$StrArr = str_split($Str); $NewStr = '';
foreach ($StrArr as $Char) {
$CharNo = ord($Char);
if ($CharNo == 163) { $NewStr .= $Char; continue; } // keep £
if ($CharNo > 31 && $CharNo < 127) {
$NewStr .= $Char;
}
}
return $NewStr;
}
Run Code Online (Sandbox Code Playgroud)
这个怎么运作:
echo RemoveBS('Hello õhowå åare youÆ?'); // Hello how are you?
Run Code Online (Sandbox Code Playgroud)
czu*_*zuk 18
试试这个:
$newtitle = html_entity_decode($newtitle, ENT_QUOTES, "UTF-8")
Run Code Online (Sandbox Code Playgroud)
如果这不是解决方案,请浏览此页面http://us2.php.net/manual/en/function.html-entity-decode.php
小智 13
这将从字符串中删除所有非ascii字符/特殊字符.
//Remove from a single line string
$output = "Likening ‘not-critical’ with";
$output = preg_replace('/[^(\x20-\x7F)]*/','', $output);
echo $output;
//Remove from a multi-line string
$output = "Likening ‘not-critical’ with \n Likening ‘not-critical’ with \r Likening ‘not-critical’ with. ' ! -.";
$output = preg_replace('/[^(\x20-\x7F)\x0A\x0D]*/','', $output);
echo $output;Run Code Online (Sandbox Code Playgroud)
我解决了这个问题.似乎是一个简短的修复,而不是更大的问题,但它的工作原理.
$newtitle = str_replace('’', "'", $newtitle);
Run Code Online (Sandbox Code Playgroud)
我还发现这个有用的snippit可以帮助其他人解决同样的问题;
<?
$find[] = '“'; // left side double smart quote
$find[] = 'â€'; // right side double smart quote
$find[] = '‘'; // left side single smart quote
$find[] = '’'; // right side single smart quote
$find[] = '…'; // elipsis
$find[] = '—'; // em dash
$find[] = '–'; // en dash
$replace[] = '"';
$replace[] = '"';
$replace[] = "'";
$replace[] = "'";
$replace[] = "...";
$replace[] = "-";
$replace[] = "-";
$text = str_replace($find, $replace, $text);
?>
Run Code Online (Sandbox Code Playgroud)
感谢大家的时间和考虑.
是的,这对我不起作用.这是什么解决方法? - vaichidrewar 3月12日22:29
将其添加到HTML头部(或者如果已经存在则修改):
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Run Code Online (Sandbox Code Playgroud)
这会将有趣的字符 "â€"编码为UTF-8,以便str_replace()函数正确解释它们.
或者你可以这样做:
ini_set('default_charset', 'utf-8');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
52521 次 |
| 最近记录: |