Welcome, Guest
  • Author Topic: Guestbook chokes on special characters  (Read 1161 times)

    Beto

    • Server what's that
    • *
    • Posts: 3
      • View Profile
      • Email
    Guestbook chokes on special characters
    « on: 04/03/03, 13:41 »
    Hi again, well I'm finally getting the guestbook working locally, but I have a problem yet to solve: when some could enter a set of characters as emoticons like :-) , :-( , or the "@" symbol etc in the Comments section, the guestbook chokes itself at the time of submitting.

    I have tried adding some lines in the PHP code...

    Code: [Select]

    $Comments= ereg_replace(":-)", "\:\-\)", $Comments);


    or deleting these lines, but even so it doesn't work. Any ideas? (I'm not yet quite skilled on PHP, evidently)



    maxdido

    • Jr. Programmer
    • **
    • Posts: 58
      • View Profile
      • Email
    Re:Guestbook chokes on special characters
    « Reply #1 on: 04/04/03, 07:54 »
    what if you do this :

    $comments   = ereg_replace("[^A-Za-z0-9 \:\(\)\.\,\@\-\/\'\?\!]", "", $comments);

    i'm not sure, give it a try and let me know.

    max.

    jose

    • Server what's that
    • *
    • Posts: 8
      • View Profile
      • Email
    Re:Guestbook chokes on special characters
    « Reply #2 on: 04/04/03, 19:22 »
    hi,
    i think i have the same problems you've had,
    can you please send me your php file, please....

    here's is my script but i don't really know what the problem is:

    <?php
          $Name = ereg_replace ("[^A-Za-z0-9 ]", "", $Name);
        $Email = ereg_replace ("[^A-Za-z0-9 \@\.\-\/\']", "", $Email);
          $Comments = ereg_replace ("[^A-Za-z0-9 \@\.\-\/\']", "", $Comments);

          $Website = eregi_replace ("http://", "", $Website);
          $Website = ereg_replace ("[^A-Za-z0-9 \@\.\-\/\'\~]", "", $Website);

          $Name = stripslashes ($Name);
          $Email = stripslashes ($Email);
          $Website = stripslashes ($Website);
          $Comments = stripslashes ($Comments);

          if ($Submit == "Yes") {
             $filename = "GuestBook.txt";
             $fp = fopen ( $filename,"r");
             $OldData = fread ($fp, 80000);
             fclose ( $fp );
             $Today = (date ("l dS of F Y ( h:i:s A )",time()));

             $Input = "Name: <b>$Name</b><br>Email: <b><u><a href=\"mailto:$Email\">$Email</a></b></u><br>
                     Website: <b><u><a href=\"http://$Website\" target=\"_blank\">$Website</a></b></u><br>Comments:
                     <b>$Comments</b><br><i><font size=\"-1\">Date: $Today</font><br><br>.:::.";

             $New = "$Input$OldData";
       
             $fp = fopen ( $filename,"w");
             fwrite ($fp, $New, 80000);
             fclose ( $fp );
          }
          $filename = "GuestBook.txt";
          $fp = fopen ( $filename,"r");
          $Data = fread ($fp, 80000);
          fclose ( $fp );

          $DataArray = split (".:::.", $Data);

          $NumEntries = count ($DataArray) - 1;

       print "&TotalEntries = $NumEntries &NumLow = $NumLow &NumHigh = $NumHigh &Guest Book=";
          for ($n = $NumLow; $n < $NumHigh; $n++) {
          print "$DataArray[$n]";
             if (!$DataArray[$n]) {
             Print "<br><br><b>No More entries</b>";
             exit;
             }}
             
    ?>
    « Last Edit: 04/04/03, 19:52 by jose »

    jose

    • Server what's that
    • *
    • Posts: 8
      • View Profile
      • Email
    Re:Guestbook chokes on special characters
    « Reply #3 on: 04/04/03, 19:48 »
    hi beto,
    i can solv your problem:
    delete the following lines:

     $Name = ereg_replace ("[^A-Za-z0-9 ]", "", $Name);
       $Email = ereg_replace ("[^A-Za-z0-9 \@\.\-\/\']", "", $Email);
          $Comments = ereg_replace ("[^A-Za-z0-9 \@\.\-\/\']", "", $Comments);

               $Website = ereg_replace ("[^A-Za-z0-9 \@\.\-\/\'\~]", "", $Website);

          $Name = stripslashes ($Name);
          $Email = stripslashes ($Email);
          $Website = stripslashes ($Website);
          $Comments = stripslashes ($Comments);
    « Last Edit: 04/04/03, 19:50 by jose »