Jump to content

[SOLVED] hi guys and girls! need some help with this lighweight blog


dubson

Recommended Posts

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

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']));
?>

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.