Jump to content

New to PHP - Need help with Content Formatting


xiledweb

Recommended Posts

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&amp;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&amp;page=$nextpage\">".
      'Next Page</a></p>';
}

?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.