View Full Version : Help - my PHP script is writing chinese characters into my index

01-23-2007, 01:33 PM
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 :/
EDIT: It does add a new post now :) -- still chinese char problem

This is the code:

if (isset($_POST['pass']))
$kode = $_POST['pass'];
$password = fopen("password.txt","r") or exit("Error #1");
$pass = fgets($password);

$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";
$filnavn = "blogpost/" . $number . ".txt";
$file = fopen("$filnavn","w") or exit("Error #3");
$skriv = "<h3>$title</h3><br><p>Forfatter: $author</p><br><br><p>$message</p>";
else {
echo "Kun for brugere";
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<h1>Bidrag til siden</h1>
$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>";
echo fgets($file)."<br>";
echo "</p>";


Which is recieved from this form:

<form action="read.php" method="post">
<h5>Titel:</h5><input type="text" name="title"><br>
<p>Forfatter:</p><input type="text" name="author"><br>
<textarea name="tekst" rows="6" cols="20"></textarea><br>
<p>Password</p><input type="password" name="pass">
<input type="submit" value="Post it!">

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

For reference, it doesn't evene add the symbol I need :/

01-23-2007, 02:44 PM
Right after <html> insert this line:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

See if that helps the output.


Not creating a new file, but you get no errors?

Perhaps the directory you are writing to does not have
permissions set. CHMOD the permission of your directory to 777.

01-23-2007, 02:54 PM
Unfourtunatly, that didn't solve it :(.. However, it creates new files now, thank you :)

I've attached a picture of what it creates instead of the .. 1 and 2 I put there to test it..

01-23-2007, 03:54 PM
See if you can use &pound; instead ...

Here's a list of special HTML characters ...


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum