brosjr Posted January 4, 2011 Share Posted January 4, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/223358-break-lines/ Share on other sites More sharing options...
dreamwest Posted January 4, 2011 Share Posted January 4, 2011 Its actually $text = str_replace("\\n", "", $text ); or even better $text = preg_replace('!\s+!', ' ', $text); Quote Link to comment https://forums.phpfreaks.com/topic/223358-break-lines/#findComment-1154605 Share on other sites More sharing options...
Adam Posted January 4, 2011 Share Posted January 4, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/223358-break-lines/#findComment-1154609 Share on other sites More sharing options...
brosjr Posted January 4, 2011 Author Share Posted January 4, 2011 Thankx dreamwest and MrAdam, both worked perfectly. The point I was missing was the single slash to set the second value into str_replace: $text = str_replace("/n", '', $text ); Quote Link to comment https://forums.phpfreaks.com/topic/223358-break-lines/#findComment-1154620 Share on other sites More sharing options...
Adam Posted January 4, 2011 Share Posted January 4, 2011 You mean backslash, not "single slash"? Just looked back at your post and realized you were using a forward-slash. Quote Link to comment https://forums.phpfreaks.com/topic/223358-break-lines/#findComment-1154622 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.