Skip to content
Advertisement

Why is PHP explode keeping the n? [closed]

Under Linux, I’m submitting a form containing text with n as the line ending. That’s the HTML:

JavaScript

EDIT: In PHP, I do:

JavaScript

In the source code, after submitting a small text, I get:

JavaScript

I only have one n for each paragraph of the original text, so why do they remain in the array after calling the first explode?

EDIT2:

Now I understand it even less!

I copied the original file to Bless Hex Editor, and it shows a single 0A (n) after each paragraph. PHP, however, outputs nothing inside the brackets for echo "[".strpos($t,"n")."]"; and numeric positions for echo "[".strpos($t,"r")."]";.

Did my computer just went nuts or is it me?

PS: Now Bless just crashed… 🙁

Advertisement

Answer

Use preg_split and run this regular expression:

JavaScript

Should work, no matter what environment your input is coming from

Here’s a fiddle

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement