0
我试图从字符串中删除以下字符
。但只有»¿
正在被删除。从正则表达式中删除字符串
Code:
protected function removeSpecialChars($comment)
{
//Remove ''
return preg_replace('/[]+/', '', $comment);
}
Input:
Your spelling is amazing
Output:
Your spellingï is amazing
任何帮助将不胜感激 - 这是让我发疯的。
UPDATE
感谢您所有的意见。我从JSON网址获取字符串 - 特别是来自Google的GData
。我用一个普通的字符串测试了代码,它工作正常,但是在JSON上测试它时不起作用。
代码从JSON网址评论:
$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的字符编码做...
您可以更具体地了解您的PHP,Web服务器和操作系统版本吗?对我来说,它的工作很好! – tuxnani
@tuxnani同样在这里。 – melwil
检查执行在这里:http://codepad.org/myrBukT8 – tuxnani