fri3ndly Posted February 4, 2008 Share Posted February 4, 2008 Hiya I have a database table with a row containing text in paragraphs. I have a textfield in an admin control panel that will bring up that text for editing, but I do not want it to display <p></p> where paragraphs are, I want it to display as it would on a webpage in paragraphs instead to make it easier for edititng. Can someone help me achieve this? I have tried strip tags, but this just makes all of the text one paragraph. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/89362-solved-displaying-paragraphs-in-textbox/ Share on other sites More sharing options...
Aureole Posted February 4, 2008 Share Posted February 4, 2008 If you're wanting to show "<" and ">" etc. inside a textarea, I believe you need to convert them into their HTML entity counterparts. Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/89362-solved-displaying-paragraphs-in-textbox/#findComment-457594 Share on other sites More sharing options...
willpower Posted February 4, 2008 Share Posted February 4, 2008 i think that he is trying to remove them, either use str_replace or integrate a rte(rich text editor) Quote Link to comment https://forums.phpfreaks.com/topic/89362-solved-displaying-paragraphs-in-textbox/#findComment-457596 Share on other sites More sharing options...
fri3ndly Posted February 4, 2008 Author Share Posted February 4, 2008 Im trying to remove the tags, but have the text display as formatted, is this possible without using an html editor? If using str_replace, what do i replace the <p> tags with? Quote Link to comment https://forums.phpfreaks.com/topic/89362-solved-displaying-paragraphs-in-textbox/#findComment-457600 Share on other sites More sharing options...
Aureole Posted February 4, 2008 Share Posted February 4, 2008 Try something like: <?php str_replace( '<p>', '', $v ); str_replace( "</p>", "\n", $v ); ?> ...where $v is the content you want to show in the textarea. I'm not sure if "\n" will work, if not just change the second parameter of the second str_replace to ""... but I added the "\n" there so that... well if you didn't then I think it'd be all crumpled up. Quote Link to comment https://forums.phpfreaks.com/topic/89362-solved-displaying-paragraphs-in-textbox/#findComment-457601 Share on other sites More sharing options...
fri3ndly Posted February 4, 2008 Author Share Posted February 4, 2008 Thanks, I can see how that could work, but it seems to be displaying the paragraphs tags. Is there a way to reverse a function like this: function formatString($string) { $x_string = explode("\r\n\r\n",trim($string)); // explode on double carriage returns $string = str_replace('<p></p>','','<p>' . implode('</p><p>',$x_string) . '</p>'); return $string; } This function will make sure that if paragraphs are entered in a textbox, the <p> tags are included, so I thought there must be a way to reverse it? Quote Link to comment https://forums.phpfreaks.com/topic/89362-solved-displaying-paragraphs-in-textbox/#findComment-457603 Share on other sites More sharing options...
fri3ndly Posted February 4, 2008 Author Share Posted February 4, 2008 bump Quote Link to comment https://forums.phpfreaks.com/topic/89362-solved-displaying-paragraphs-in-textbox/#findComment-457627 Share on other sites More sharing options...
fri3ndly Posted February 4, 2008 Author Share Posted February 4, 2008 Just incase this helps anybody else, I found a solution to the problem, although its probably not the best thing to do, it works! <?php function nl2p($your_text) { return "" . str_replace("</p><p>", "\n\n", $your_text) . ""; } ?> Then, where you need to format text for a textbox display call the function like this: <?php echo strip_tags (nl2p($your_text)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/89362-solved-displaying-paragraphs-in-textbox/#findComment-457663 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.