Remove line from the beginning of a string?

HelloInsomnia

Elite Member
Joined
Mar 1, 2009
Messages
1,801
Reaction score
3,042
I am a total PHP nub - it's been years since I attempted to make anything. Finally I had a good idea and decided to give it a shot. Long story short I'm stuck on a problem.

Here is the issue:

Code:
foreach(explode("\n", $x) as $y) {

I want to display $y in a line with a bunch of stuff in front of it and after it on the same line.

But it keeps adding a line break into the string because it has to go to the new line to get the input (this is taking it from a textarea with many lines).

I tried trim and ltrim and those didn't seem to work.

Any help would be awesome.
 
sometimes the textarea contains \r\n - maybe that's the problem. If so, you can use replace them before exploding.

Haven't tested but maybe something like this :

PHP:
 $x = preg_replace('/\r\n|\r/', "\n", $x);
foreach(explode("\n", $x) as $y) {
 
Thanks, Appman360 your solution worked
 
Back
Top