Jump to content

Break lines


Recommended Posts

Good morning,


I passed a bunch of HTML tags over a function that delete then, keeping just the text between. The problem is, after that all the tags were replaced by line breaks. Something like this before the function:








After the function the 4 tags were correctly removed but instead i receive just the string "Text" I receive 2 line breaks, the "Text" and other 2 line breaks, like this:








In HTML code this line breaks has no tags like <br> or <p> it's just blanck lines. I need to get just the text, how can I get rid of then? I tried this and also didn't work.


$text = str_replace("/n", "", $text );



Danilo Jr.

Link to comment
Share on other sites

Its actually


$text = str_replace("\\n", "", $text );


Escaping the backslash will look for the literal "\n", not the newline character. It's possible the string has DOS/Windows carriage return characters ("\r") in it as well. Try this:


$text = str_replace(array("\n", "\r"), '', $text);

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.