PHP preg_replace 替换换行符 [英] PHP preg_replace replacing line break

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

问题描述

使用

$arr=array_values($arr); // Renumber array

我意识到在其中一个数组字符串中引入了换行符,这是我不想要的.

I realized that a line break is being introduced into one of the array strings, which I don't want.

我的字符串来自:

财产输入

到财产

类型

无论如何我都在使用:

$newelement = preg_replace("/[^A-Za-z0-9\s\s+]/", " ", $element);

在数据库插入之前已经去掉了不需要的字符,所以我试着把它改成:

already to remove unwanted characters prior to database insertion, so I tried to change it to:

 $newelement = preg_replace("/[^A-Za-z0-9\s\s+'<br>''<br>''/n''/cr']/", " ", $element);

但是没有变化,?换行/换行/回车仍然存在.

But there is no change, and the ?line feed/line break/carriage return is still there.

我是否正确执行了 preg_replace 调用?

Am I doing the preg_replace call correctly?

推荐答案

那个 preg 看起来有点复杂.然后你在开头有 ^ 作为 not A-Z ... 或换行符.所以你不想替换换行符?

That preg looks a bit complicated. And then you have ^ in the beginning as not A-Z... or linefeed. So you don't want to replace linefeed?

怎么样

$newelement = preg_replace("/[\n\r]/", "", $element);

$newelement = preg_replace("/[^A-Za-z ]/", "", $element);

\s 也匹配换行符 (\n).

\s also matches linefeed (\n).

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

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