PHP删除换行符或CR LF失败 [英] PHP remove line break or CR LF with no success

查看:245
本文介绍了PHP删除换行符或CR LF失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个删除php换行符的操作,但没有成功,我尝试了所有替换代码,但仍然得到这些换行符,我创建了一个json文件,由于这些行,我无法从jquery的jsonp中读取它打破似乎打破了一切.

I did a function to remove line break with php with no success, i tryed all replace code and i still get these line break, i create a json file and i can't read it from jsonp with jquery because of these line break seem to break it all.

function clean($text)
{
$text = trim( preg_replace( '/\s+/', ' ', $text ) );  
$text = preg_replace("/(\r\n|\n|\r|\t)/i", '', $text);
return $text;
}

当我查看源代码时,所有href,img和br中都有换行符 这是一个json_encode输出 示例:

When i look at the source, there some line break appening in all href, img and br this is a json_encode output example:

<a
href=\"http:\/\/example.com\/out\/content\/\" title=\"link to content website\">

换行后a. 是img src和br

line break afer a. it's hapenig to img src and br

我可以删除这些的唯一方法是破坏它

the only way i can remove these break it with

$text = preg_replace("/\s/i", '', $text);

但是您要确定,所有字符串中都没有空格,这也不是我们想要的.

But you understant that there's no space left in all the string and it's not what we want.

推荐答案

此替换对我来说效果更好:

this replace works better for me:

= str_replace (array("\r\n", "\n", "\r"), ' ', $text)

这篇关于PHP删除换行符或CR LF失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆