Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

php guestbook and file writing multibyte character sets

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

php guestbook and file writing multibyte character sets

Postby pheck » Tue Dec 31, 2002 2:18 am

http://hawaiian-wedding.nolibravo.com

i am having trouble with my guestbook in writing japanese text (multibyte) to my guestBook.txt file. as you can see, the guestbook displays japanese fine
(.txt is saved in UTF-8 unicode format), but i think the problem is in going from submission to writing to the txt file, so this leads me to think
it's somewhere in my php script. my contact page will send japanese text no problem (as long as the recipient email will read UTF-8).

what do i have to do scripting-wise to get this bugger to write japanese text? thanks in advance for your help. here's my php code for guestBook.php:

Code: Select all
<?
############### Begin Time Zone Friendly GuestBook Script #####################################

##The first 3 lines use a regular expression to match a pattern then replace it with nothing.  The only reason for this is so we only allow necessary characters to be entered into the guestbook. This also takes out slashes which are sometimes added in the post headers to make the string friendly.  They are taken out here.

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

##Make the entry Flash safe by removing the Flash variable symbol "&"

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

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

 ##################################################
##################################
########### Reading and Writing the new data to the GuestBook Database #############

if ($Submit == "Yes") {
#Next line tells the script which Text file to open.
   $filename = "guestBook.txt";

#Opens up the file declared above for reading

   $fp = fopen( $filename,"rb");
   $OldData = fread($fp, 80000);
   fclose( $fp );

#Gets the current Date of when the entry was submitted and adds $time_diff hours onto it (difference between server time and Japan time)
#For subtracting hours, just use a negative number for $time_diff
   $time_diff = 17;
   $timestamp = time();
   $date_time_array = getdate($timestamp);
   $hours = $date_time_array ["hours"];
   $minutes = $date_time_array ["minutes"];
   $seconds = $date_time_array ["seconds"];
   $month = $date_time_array ["mon"];
   $day = $date_time_array ["mday"];
   $year = $date_time_array ["year"];
   $timestamp = mktime($hours + $time_diff, $minutes, $seconds, $month, $day, $year);
   $Today = date ("l dS of F Y h:i:s A (\J\a\p\a\\n)", $timestamp);

#Puts the recently added data into html format that can be read into the Flash Movie.

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

#This Line adds the 'GuestBook=' part to the front of the data that is stored in the text file.  This is important because without this the Flash movie would not be able to assign the variable 'GuestBook' to the value that is located in this text file

   $New = "$OldData$Input";

#Opens and writes the file.

   $fp = fopen( $filename,"w+b");
   fwrite($fp, $New, 80000);
   fclose( $fp );

#Send an email to the site admin that a new post has been made in the guestbook.

   $EmailBody = "$Name has just submitted an entry into the guestbook.  Here are the comments:\n\n$Comments\n";
   $to  = "Hawaiian Wedding <XXXX@XXXX.com>";
   mail($to, "HGL Guestbook Entry", $EmailBody, "From: XXXX@XXXX.com");
}
 ##################################################
##################################
########## Formatting and Printing the Data from the Guestbook to the Flash Movie ##

#Next line tells the script which Text file to open.
   $filename = "guestBook.txt";

#Opens up the file declared above for reading

   $fp = fopen( $filename,"rb");
   $Data = fread($fp, 80000);
   fclose( $fp );

#Splits the Old data into an array anytime it finds the pattern .:::.
   $DataArray = split (".:::.", $Data);

#Counts the Number of entries in the GuestBook
   $NumEntries = count($DataArray) - 1;

   print "&TotalEntries=$NumEntries&NumLow=$NumLow&NumHigh=$NumHigh&GuestBook=";
   for ($n = $NumLow; $n < $NumHigh; $n++) {
   if ($n > count($DataArray) - 1) {
   Print "<br><br><b>No More entries</b>";
   exit;
   }
   print $DataArray[$n];
}
   


 ##################################################
##################################
###############  End GuestBook Script
?>
pheck
New php-forum User
New php-forum User
 
Posts: 2
Joined: Tue Dec 31, 2002 2:15 am
Location: San Franny

Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.