PHP How to replace multiple spaces, tabs, newlines with one

  html, php, regex, removing-whitespace

I’m trying to make a blog with text input, but I don’t make it to save the text properly in the database.

I want to replace every multiple space and newline with just one space/newline.

I looked up alot now but don’t find a working solution I tried this: Replace multiple newlines, tabs, and spaces . Didn’t work properly.

I want it like this:

1    2
3

4


   5    6
  7

To be:

1 2
3

4

5 6

7

Is there any regex that could help me?
Thanks very much in advance.
Best reguard, Tobi.

Source: Ask PHP

LEAVE A COMMENT