Nuggit Posted February 25, 2007 Share Posted February 25, 2007 EDIT: There's HTML in what I typed, so it's all screwy. I guess... Quote my post to see what I actually said? I have a thing where it takes input, and formats it with HTML so that linebreaks are shown. I've got it so that it'll take every line break and place a <br /> on it (but not get rid of the line break). That became a problem, because every time I edited it, the line breaks would double, but I fixed it by making it replace <br /><br /> with just one <br />. So that's working. But I still want to know how I can actually get rid of it, because it's bothering me, the way <br /> is placed at the beginning of each newline. I want it to be at the end. A backspace thing (like \b maybe?) would be really useful. I can't find it, though. So I'm probably just making it up. Am I? This is my code: $convertthis = array(' ','<p><p>','</p></p>','<br /><br />'); $tothis = array('<br />','<p>','</p>','<br />'); $edit1 = substr_replace($_POST['blurb'],"<p>",0,0); //beginning of string $edit2 = substr_replace($edit1,"</p>",strlen($edit1),0); //end of string $blurb = str_replace($convertthis,$tothis,$edit2); //replacing line breaks, getting rid of doubles (Yeah, I put actual line breaks in $convertthis. I tried to make it search for '\n\n' but for some reason it wouldn't find it. So, just a by-the-way question... is this normal?) Quote Link to comment https://forums.phpfreaks.com/topic/39992-would-like-help-with-line-breaks-and-str_replace/ Share on other sites More sharing options...
wildteen88 Posted February 25, 2007 Share Posted February 25, 2007 If you want to convert line breaks to html line breaks then use nl2br()- It does it all for you. Also you should only run that code when you get it out of the database. Do not run this code when adding the data into the database. That way when you go to edit it later it wont duplicate the line breaks. Keep everything in its raw state when being stored in the database Only do the syntax formatting later on. Also note when posting html code in posts use the [nobbc][/nobbc] tags. I have edited your post with this addition. Quote Link to comment https://forums.phpfreaks.com/topic/39992-would-like-help-with-line-breaks-and-str_replace/#findComment-193675 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.