我做了一个功能,删除换行符与PHP没有成功,我tryed所有替换代码,我仍然得到这些换行符,我创建一个JSON文件,我不能用jquery从jsonp中读取它,因为这些换行符似乎打破了这一切。PHP删除换行符或CR LF没有成功
function clean($text)
{
$text = trim(preg_replace('/\s+/', ' ', $text));
$text = preg_replace("/(\r\n|\n|\r|\t)/i", '', $text);
return $text;
}
当我看源,有一些换行符在所有HREF,IMG和Br appening这是一个json_encode输出 例如:
<a
href=\"http:\/\/example.com\/out\/content\/\" title=\"link to content website\">
换行符AFER一个。 它hapenig到IMG SRC和BR
的唯一途径,我可以删除这些打破它与
$text = preg_replace("/\s/i", '', $text);
但你understant,有没有留在所有字符串的空间,这不是我们想要的。
感谢的为所有,但到现在为止,这些解决方案的工作。但通常大多数这些解决方案应该工作,但我不明白为什么我的情况下它不 – Gino 2012-03-12 15:32:55
我发现修复它的唯一方法是 '$ allcontent = preg_replace('/ Gino 2012-03-22 03:53:14
I hit the same and no solutions in this post worked for me. I found another similar post and this solution worked for me...hence posting it here: http://stackoverflow.com/a/3340510/405117 – Vikram 2012-08-01 20:39:45