blog with BBcodes
Posted: Sun Feb 24, 2013 1:23 pm
Hi!I have complited this nice blog tutorial,everything works fine,thanks to Author of this tutorial!
And now I have a question, is it possible to make a BBcodes in Blog?When user write (some text) it will show text in bold?
I tried to add this parser or how it's called for example into my blog_read.php but and other stuff doesnt work, it just outputs without converting..
so here is that parser or what...and it works
So if I try like this,I made a new separate page ,than it works.So the question is,where I should put this code into my blog_read and other blog files?I hope for your help"BetterPhp"
here is my experiment with blog_read.php and with parser inside
And now I have a question, is it possible to make a BBcodes in Blog?When user write (some text) it will show text in bold?
I tried to add this parser or how it's called for example into my blog_read.php but and other stuff doesnt work, it just outputs without converting..
so here is that parser or what...and it works
<html> <head> <title>BBCode Parser</title> </head> <body> <?php if(isset($_POST['message'])) { $text = $_POST['message']; $text = stripslashes($text); $text = htmlspecialchars($text); $text = nl2br($text); $text = preg_replace('#\[b\](.+)\[/b\]#isU', '<b>$1</b>', $text); $text = preg_replace('#\[i\](.+)\[/i\]#isU', '<i>$1</i>', $text); $text = preg_replace('#\[u\](.+)\[/u\]#isU', '<u>$1</u>', $text); $text = preg_replace('#\[img\](.+)\[/img\]#isU', '<img src="$1" />', $text); echo $text; } else { ?> <form action='bbcodeparser.php' method='POST'> <textarea name='message'>TEXT GOES HERE</textarea></br> <input type='submit' value='Submit' /> </form> <?php } ?> </body> </html>
So if I try like this,I made a new separate page ,than it works.So the question is,where I should put this code into my blog_read and other blog files?I hope for your help"BetterPhp"
here is my experiment with blog_read.php and with parser inside
<?php include('core/init.inc.php'); if (isset($_GET['pid'], $_POST['user'], $_POST['body'])){ if (add_comment($_GET['pid'], $_POST['user'], $_POST['body'])){ header("Location: blog_read.php?pid={$_GET['pid']}"); }else{ header('Location: blog_list.php'); } } ?> <!DOCTYPE HTML> <html lang="en" class="no-js"> <head> <meta charset="UTF-8"> <title>SITENAME</title> </head> <body> <div> <?php if (isset($_GET['pid']) === false || valid_pid($_GET['pid']) === false){ echo 'Invalid post ID.'; }else{ $post = get_post($_GET['pid']); ?> <h2><?php echo $post['title']; ?></h2> <h4>By <?php echo $post['user']; ?> on <?php echo $post['date']; ?> (<?php echo count($post['comments']); ?> comments)</h4> <hr /> <p><?php echo $post ['body']; ?></p> <hr /> <?php foreach ($post['comments'] as $comment){ ?> <h4>By <?php echo $comment['user']; ?> on <?php echo $comment['date']; ?></h4> <p><?php echo $comment['body']; ?></p> <hr /> <?php } ?> <?php if(isset($_POST['body'])) { $text = $_POST['body']; $text = stripslashes($text); $text = htmlspecialchars($text); $text = nl2br($text); $text = preg_replace('#\[b\](.+)\[/b\]#isU', '<b>$1</b>', $text); $text = preg_replace('#\[i\](.+)\[/i\]#isU', '<i>$1</i>', $text); $text = preg_replace('#\[u\](.+)\[/u\]#isU', '<u>$1</u>', $text); $text = preg_replace('#\[img\](.+)\[/img\]#isU', '<img src="$1" />', $text); echo $text; } else { ?> <form action='' method="POST"> <p> <label for="user">Name</label> <input type="text" name="user" id="user" /> </p> <p> <textarea name="body">text here</textarea> </p> <p> <input type="submit" value="Add Comment" /> </p> </form> <?php } } ?> </div> </body> </html>