Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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:
    PHP 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);

    ?>
    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>
    Any of you guys know a soloution to this :/?

    For reference, it doesn't evene add the £ symbol I need :/
    Last edited by Cbrams; 01-23-2007 at 01:32 PM.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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..
    Attached Thumbnails Attached Thumbnails Help - my PHP script is writing chinese characters into my index-error.jpg  

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    See if you can use &pound; instead ...

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

    http://www.utexas.edu/learn/html/spchar.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •