相关疑难解决方法(0)

替换多个换行符,制表符,空格

我想用一个Newline字符替换多个Newline字符,用一个空格替换多个空格.
我尝试过但preg_replace("/\n\n+/", "\n", $text);失败了!

我也在$ text上进行格式化.

$text = wordwrap($text, 120, '<br/>', true);
$text = nl2br($text);
Run Code Online (Sandbox Code Playgroud)

$ text是用户为BLOG拍摄的大文本,为了更好的格式化,我使用wordwrap.

php regex preg-replace

31
推荐指数
3
解决办法
7万
查看次数

PHP 中删除字符串中所有类型的制表符、空格、回车符

我有这样的文本数据:

                Learn More

        Hide [x]








                            Colors



                    Fetching Colors description...




            Show more topics







                            Art exhibitions



                    Fetching Art exhibitions description...








                            Abstract art



                    Fetching Abstract art description...








                            Representational art



                    Fetching Representational art description...
Run Code Online (Sandbox Code Playgroud)

我希望能够删除所有回车符,所以它变成这样:

Learn More Hide [x] Colors Fetching Colors description... Show more topics
Run Code Online (Sandbox Code Playgroud)

我如何在 PHP 中执行此操作?请注意,字符串可能是 UTF-8 字符串,我们需要考虑各种制表符、回车符和空格字符。(我正在思考编译器中使用的标记器算法,其中处理多个回车符和空格字符。)

php

-1
推荐指数
1
解决办法
2732
查看次数

标签 统计

php ×2

preg-replace ×1

regex ×1