我正在尝试
从字符串中删除以下字符。但是只有»¿
被删除。
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 的字符编码有关...