Jump to content

Break lines


brosjr

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:

 

<tr>

<td>

Text

</tr>

</td>

 

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:

 

 

 

Text

 

 

 

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 );

 

Thanks

Danilo Jr.

Link to comment
https://forums.phpfreaks.com/topic/223358-break-lines/
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
https://forums.phpfreaks.com/topic/223358-break-lines/#findComment-1154609
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.