How to split TextArea Input at every line break PHP

174 Views Asked by At

i have some trouble splitting my TextArea Input at every linebreak: If I insert this text:

"Hello:
 world"

Then I have this string as my value Hello: world

I tried something like

$input = str_replace(" ", "", $input);

OR

$input = trim($input);

But nothing changes. I want to remove all the linebreaks because later when I output the string with htmlspecialchars it fills the line breaks with something like "

&#"; And I want to remove it. So I thought i can split the string and after that, add it up together so all my linebreaks will be removed.

1

There are 1 best solutions below

2
Wahyu Kristianto On

You can use :

$input = str_replace(["\r", "\n"], '', $input);

Or

preg_replace("/\r|\n/", "", $input);