tecmeister Posted November 15, 2009 Share Posted November 15, 2009 Hi Guys, I'm trying to replace <br /> with an empty space. I'm removing the br / but not the < >. This is the code I'm using: $about = $row['about']; $br = "<br />"; echo preg_replace($br," ",nl2br($about)); How do I remove the < > aswell? Thanks, tecmeister. Quote Link to comment https://forums.phpfreaks.com/topic/181633-solved-replace-a-with-an-empty-space/ Share on other sites More sharing options...
Alex Posted November 15, 2009 Share Posted November 15, 2009 You shouldn't be using PCRE functions when you don't need to, they use a lot more resources than you need to waste. Instead use str_replace(). The reason why it's only replacing br / is because preg_replace is trying to use < and > as delimiters. echo str_replace("<br />", " ", nl2br($about)); Quote Link to comment https://forums.phpfreaks.com/topic/181633-solved-replace-a-with-an-empty-space/#findComment-958036 Share on other sites More sharing options...
tecmeister Posted November 15, 2009 Author Share Posted November 15, 2009 Thank you very much again Alex for your help Quote Link to comment https://forums.phpfreaks.com/topic/181633-solved-replace-a-with-an-empty-space/#findComment-958037 Share on other sites More sharing options...
salathe Posted November 15, 2009 Share Posted November 15, 2009 I am intrigued to know why you want to undo what nl2br does, and replace it with something else. Why go through the process of adding BR tags only to substitute them with something else? Quote Link to comment https://forums.phpfreaks.com/topic/181633-solved-replace-a-with-an-empty-space/#findComment-958039 Share on other sites More sharing options...
Alex Posted November 15, 2009 Share Posted November 15, 2009 Yea, why not just do: echo str_replace("\n", " ", $about); Quote Link to comment https://forums.phpfreaks.com/topic/181633-solved-replace-a-with-an-empty-space/#findComment-958040 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.