xiledweb Posted November 19, 2006 Share Posted November 19, 2006 Ok, I would like my article submission for my audience to be as simple as possible - therefore very little knowledge of HTML would even be necessary. Everything outputs as it should right now, but the content submitted is not broken into paragraphs, i.e the text is continuous. What I want to achieve is that when the user hits 'enter', the interpretation will be that of a new paragraph (or unless there's a better way to do it).Here is what I'm working with: [code]// Filter out HTML code$articletext = htmlspecialchars($articletext);// If no page specified, default to the first page ($page = 0)if (!isset($_GET['page'])) { $page = 0;} else { $page = $_GET['page'];}// Split the text into an array of pages$textarray = spliti('\[PAGEBREAK]', $articletext);// Select the page we want$articletext = $textarray[$page];// Bold and italics$articletext = str_replace(array('[b]', '[B]'), '<strong>', $articletext);$articletext = str_replace(array('[eb]', '[EB]'), '</strong>', $articletext);$articletext = str_replace(array('[i]', '[I]'), '<em>', $articletext);$articletext = str_replace(array('[ei]', '[EI]'), '</em>', $articletext);// Paragraphs and line breaks function to_paragraphs($text) { $str = ''; foreach (preg_split('#(\r\n|\r|\n)+\s*(\r\n|\r|\n)#', trim((string) $text)) as $p) { $str .= "<p>" . preg_replace('#\r\n|\r|\n#', "<br />\n", trim($p)) . "</p>\n"; } return $str;} // Hyperlinks$articletext = eregi_replace( '\\[L]([-_./a-z0-9!&%#?+,\'=:;@~]+)\\[EL]', '<a href="\\1">\\1</a>', $articletext);$articletext = eregi_replace( '\\[L=([-_./a-z0-9!&%#?+,\'=:;@~]+)]([^\\[]+)\\[EL]', '<a href="\\1">\\2</a>', $articletext);$PHP_SELF = $_SERVER['PHP_SELF'];if ($page != 0) { $prevpage = $page - 1; echo "<p><a href=\"$PHP_SELF?id=$id&page=$prevpage\">". 'Previous Page</a></p>';}echo "<p>$articletext</p>";if ($page < count($textarray) - 1) { $nextpage = $page + 1; echo "<p><a href=\"$PHP_SELF?id=$id&page=$nextpage\">". 'Next Page</a></p>';}?>[/code] Link to comment https://forums.phpfreaks.com/topic/27809-new-to-php-need-help-with-content-formatting/ Share on other sites More sharing options...
fert Posted November 19, 2006 Share Posted November 19, 2006 nl2br() Link to comment https://forums.phpfreaks.com/topic/27809-new-to-php-need-help-with-content-formatting/#findComment-127240 Share on other sites More sharing options...
xiledweb Posted November 19, 2006 Author Share Posted November 19, 2006 I don't suppose you could explain a little bit more? Link to comment https://forums.phpfreaks.com/topic/27809-new-to-php-need-help-with-content-formatting/#findComment-127243 Share on other sites More sharing options...
alexcmm Posted November 20, 2006 Share Posted November 20, 2006 I'm no PHP wiz, but this is what I have that works in a contact form. This is the page that is sent to... it works for me. Don't know if this helps... $comments=$_POST['comments']; $comments = [b]preg_replace("/\n/","\n<BR>\n"[/b],$comments); Link to comment https://forums.phpfreaks.com/topic/27809-new-to-php-need-help-with-content-formatting/#findComment-127267 Share on other sites More sharing options...
fert Posted November 20, 2006 Share Posted November 20, 2006 [code]$text=nl2br($text);[/code]this will change all the newlines to < br>s Link to comment https://forums.phpfreaks.com/topic/27809-new-to-php-need-help-with-content-formatting/#findComment-127269 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.