0

我正在尝试从字符串中删除以下字符。但是只有»¿被删除。

Code:

protected function removeSpecialChars($comment)
{
    //Remove ''
    return preg_replace('/[]+/', '', $comment);
}

Input:

Your spelling is amazing

Output:

Your spellingï is amazing

任何帮助将不胜感激 - 这让我发疯。

更新

感谢您的所有评论。我从 JSON url 获取字符串 - 特别GData是来自 Google。我用普通字符串测试了代码,它工作正常,但是在 JSON 上测试它时它不起作用。

从 JSON URL 获取评论的代码:

$url = 'https://gdata.youtube.com/feeds/api/videos/' . $video_id .'/comments?alt=json&max-results=50&v=2';
$comments = array();

$json   = file_get_contents($url);
$data   = json_decode($json, TRUE);

foreach($data["feed"]["entry"] as $item)
{
    array_push($comments, $item["content"]['$t']);
}

不确定它是否与 JSON 的字符编码有关...

4

2 回答 2

0

尝试添加 u 修饰符:

return preg_replace('/[]+/u', '', $comment);
于 2013-05-28T16:09:25.070 回答
0
return preg_replace("/\\357\\273\\277/um", '', $comment);
于 2013-05-28T17:49:21.247 回答