0

I need a little bit of your help if you can. I need the regular expression in php to remove multiple new lines and redundant whitespaces if occur more than 1.

for example

Hi    this  is
    a


test      code

------------------> convert above into

Hi this is
a
test code
JabberwockyDecompiler
  • 3,318
  • 2
  • 42
  • 54

1 Answers1

4

Use :

echo preg_replace("/(^\s+|\s+$)/m","\r\n",$text);

Ref: Link:

How do you trim white space on beginning and the end of each new line with PHP or regex

Community
  • 1
  • 1
Mudaser Ali
  • 3,989
  • 3
  • 25
  • 27