dubson Posted June 6, 2008 Share Posted June 6, 2008 I found this light weight login form on someones website (for the life of me I cant remember which site it was, sorry) which I've implemented into a blog (once logged in, the blog form becomes available). The part that I need help with is exporting the blog to a file, it works so far but I'm having problems using nl2br. I can see that it is getting executed in the script as it adds <br /> to the file. But as <br /> so when the file gets called to appear in the visitor blog page, instead of seeing a new line the visitor sees the actual br code. This is the blog code: <?php if (isset($_POST['message'])) { if (isset($_SESSION['token']) && $_POST['token'] == $_SESSION['token']) { $message = htmlentities(nl2br($_POST['subject'])); $message = htmlentities(nl2br($_POST['message'])); $fp = fopen('blog.php', 'a'); fwrite($fp, "<h1><p>$subject</p>$message</h1>"); fclose($fp); } } $token = md5(uniqid(rand(), true)); $_SESSION['token'] = $token; ?> Post a blog, Dub. <form method="POST" name="comments"> <input type="hidden" name="token" value="<?php echo $token;?>" /> <input type="text" name="subject" width="200px"><br /> <textarea name="message" cols="50" rows="15"></textarea><br /> <input type="submit" value="Submit"> </form> <?php readfile('blog.php'); ?> And you can see it live at http://baselinedesign.freehostia.com/blog.php (I'll leave a test blog so you can see the output). I'm guessing that you know what I want, for the new line to be implemented properly. Hope one of you can help Thanks dubson Link to comment https://forums.phpfreaks.com/topic/108995-solved-hi-guys-and-girls-need-some-help-with-this-lighweight-blog/ Share on other sites More sharing options...
RMcLeod Posted June 6, 2008 Share Posted June 6, 2008 The problem is that htmlentities is converting the < and > of the <br /> tag into < and > so that the browser will display the tag rather than the line break. Simply swap the functions round. <?php echo nl2br(htmlentities($_POST['subject'])); ?> Link to comment https://forums.phpfreaks.com/topic/108995-solved-hi-guys-and-girls-need-some-help-with-this-lighweight-blog/#findComment-559161 Share on other sites More sharing options...
dubson Posted June 6, 2008 Author Share Posted June 6, 2008 Weyhey, that worked perfect thanks a lot! Link to comment https://forums.phpfreaks.com/topic/108995-solved-hi-guys-and-girls-need-some-help-with-this-lighweight-blog/#findComment-559235 Share on other sites More sharing options...
dubson Posted June 7, 2008 Author Share Posted June 7, 2008 I found the original script, for anyone who's interested http://prdesign-studio.co.uk/HarryRoberts/index.php?2007/09/21/19/53/56-php-login-system Link to comment https://forums.phpfreaks.com/topic/108995-solved-hi-guys-and-girls-need-some-help-with-this-lighweight-blog/#findComment-559764 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.