Jump to content

Help - my PHP script is writing chinese characters into my index


Cbrams

Recommended Posts

Okay, to sum up, I have to do a school project on PHP scripting, and we ere assigned to code a blog, using only PHP, so no mySQL soloutions. I am aware that this is screwing security, but we'll have to make do :P..

The thing is, I can't find an error in this script, but everytime I try to add a post, it posts useless chinese characters in my index file, and it doesn't seem to want to create a new file for the post either :/

This is the code:[CODE]
<?php
if (isset($_POST['pass']))
{
$kode = $_POST['pass'];
$password = fopen("password.txt","r") or exit("Error #1");
$pass = fgets($password);
fclose($password);
if($kode==$pass)
{

$index = fopen("index.txt","a") or exit("Error #2");
$message = $_POST['tekst'];
$title = $_POST['title'];
$author = $_POST['author'];
$indexarray = explode("£",$index);
$number = count($indexarray);
$number = $number + 2;
$title2 = "£ $title";
fwrite($index,$title2);
$filnavn = "blogpost/" . $number . ".txt";
touch($filnavn);
$file = fopen("$filnavn","w") or exit("Error #3");
$skriv = "<h3>$title</h3><br><p>Forfatter: $author</p><br><br><p>$message</p>";
fwrite($file,$skriv);
fclose($file);
fclose($index);
}
else {
echo "Kun for brugere";
}
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<h1>Bidrag til siden</h1>
<?php
$index = fopen("index.txt","r") or exit("Error #4");
$indexarray = explode("£",$index);
$number = count($indexarray);
$number = $number + 1;
for($i=$number;$i>0;$i--) {
$file=fopen("blogpost/" . $i . ".txt","r") or exit("Error #5");
echo "<p>";
while(!feof($file))
{
echo fgets($file)."<br>";
}
fclose($file);
echo "</p>";
}
fclose($index);

?>[/CODE]

Which is recieved from this form:
[CODE]<html>
<body>
<form action="read.php" method="post">
<h5>Titel:</h5><input type="text" name="title"><br>
<p>Forfatter:</p><input type="text" name="author"><br>
<p>Tekst:</p><br>
<textarea name="tekst" rows="6" cols="20"></textarea><br>
<p>Password</p><input type="password" name="pass">
<input type="submit" value="Post it!">
</form>
</body>
</html>[/CODE]

Any of you guys know a soloution to this :/?

For reference, it doesn't evene add the £ symbol I need :/
you might try using an html entity instead of your pound symbol.. I don't know if this will fix you whole problem, but it might. The correct entity is "&pound;"

[url=http://tlt.its.psu.edu/suggestions/international/web/codehtml.html#currency]symbol entities[/url]

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.