Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: Problems with Polish letters
Forum PHP.pl > Forum > PHP
doodlebug
Hello All!
Apologies for my lack of Polish and apologies if this has gone in the wrong forum.
I'm creating a website where you enter your details in text boxes on an .html page, which you then review on a .php page.
Everything has been changed to utf-8.

The problem is when you enter Polish characters in the text box, on the next page when you review the information and say whether it's good or not, the Polish characters show up as "Auml�Auml�Auml�Aring�"

Any idea what the problem could be?

Many thanks in advance
mrok
Maybe you keep this info in DB which is not set as utf8.
Try execute
  1. SET NAMES utf8

after connect to db.
doodlebug
The problem happens before the Polish letters get to the DB. The process is like this:

index.html -> where you enter Polish characters in text fields
review.php -> you check to see if your info is correct **This is where I have the problems with the letters**
submit.php -> info is sent to DB

The code on review.php is
  1. $string1 = isset($_POST['firstname']) ? htmlentities($_POST['firstname']) : false;
  2.  
  3. if(empty($string1))
  4. {
  5.  
  6. echo("<h2>Imiê:<font color=red>Prozsê wype³niæ</font></h2>\n");
  7. $showbutton=1;
  8. }
  9. else
  10. {
  11. $firstname = ereg_replace("[^0-9a-zA-Z?±æê³ñó¶¿¼¡ÆÊ£ÑÓ¦¯¬ ]", "", $string1);
  12. echo("<h2><span class=profile>Imiê:</span> <font color=#04B404>" . $firstname . "</font></h2>\n");
  13. echo("<input type=hidden name=firstname value=" . $firstname . ">");
  14. }
koreja
Check the file encoding and set it at utf-8, next try the sugestion of @mrok.
mandragorek
I think the problem is with htmlentities. Insert it after ereg_replace.
doodlebug
Thanks for answering, however I'm a complete idiot and new to php. Do you want me to try:

$firstname = ereg_replace htmlentities("[^0-9a-zA-Z?±æê³ñó¶¿¼¡ÆÊ£ÑÓ¦¯¬ ]", "", $string1);

This gives me the error:

Parse error: syntax error, unexpected T_STRING in /home/englas/public_html/znajdejezyk.pl/studentpreinsertpl.php on line 82

I also tried:

$firstname = ereg_replace (htmlentities("[^0-9a-zA-Z?±æê³ñó¶¿¼¡ÆÊ£ÑÓ¦¯¬ ]", "", $string1));

And that gave me some warnings on the page:
Warning: htmlentities() expects parameter 2 to be long, string given in ***** on line 82

Warning: Wrong parameter count for ereg_replace() in ***** on line 82
mandragorek
I thought about
  1. $firstname = ereg_replace("[^0-9a-zA-Z?±æê³ñó¶¿¼¡ÆÊ£ÑÓ¦¯¬ ]", "", $string1);
  2. $firstname = htmlentities($firstname);


Probably after first line in your script
  1. $string1 = isset($_POST['firstname']) ? htmlentities($_POST['firstname']) : false;


in variable $string1 you get text where some letters are replaced with their html entities.
dariuszp
Hi,
first of all, use preg_replace because ereg is deprecated. Second, you should use htmlspecialchars instead of htmlentities i think. Last thing, check meta tag on the webpage if you have utf-8 encoding. After that check if you have utf-8 in your database. You receive ? because web browser don't know what to do with additional byte.

You should know that iso-8859-2 (latin2) use 1 byte to encode a character. UTF-8 need 1 byte for first 128 characters (ASCII), then 2 bytes after that.
When you display utf-8 string as latin2, all characters above US-ASCII table are displayed wrong because it display each of the two bytes separately and not as one char.
doodlebug
Thanks for the suggestion Mandragorek - but no luck sad.gif



dariuszp - thanks for the suggestion.

The meta tags are all utf 8, charsets are all UTF 8 on all pages -php and html
database: MySQL charset: UTF-8 Unicode (utf8)
MySQL connection collation: utf-8_unicode_ci

I tried preg_replace and used htmlspecialchars but it still didn't work.

I tried changing the charset to iso-8859-2 and that just messed up the whole page

LATEST NEWS*********

The code now looks like:
  1. $string1 = isset($_POST['firstname']) ? htmlentities($_POST['firstname']) : false;
  2.  
  3. if(empty($string1))
  4. {
  5.  
  6. echo("<h2>Imiê:<font color=red>Prozsê wype³niæ</font></h2>\n");
  7. $showbutton=1;
  8. }
  9. else
  10. {
  11. $firstname = preg_replace ("[^0-9a-zA-Z?±æê³ñó¶¿¼¡ÆÊ£ÑÓ¦¯¬ ]", "", $string1);
  12. $firstname = htmlspecialchars($firstname, ENT_COMPAT, 'UTF-8');
  13. echo("<h2><span class=profile>Imiê:</span> <font color=#04B404>" . $firstname .
  14.  
  15. "</font></h2>\n");
  16. echo("<input type=hidden name=firstname value=" . $firstname . ">");


This now produces a blank field rather than symbols - any ideas what's going on?
goran
Hey,

First of all look at the source code of your site for polish characters. Maybe your browser is set to some strange encoding smile.gif.

Second thing: try to add this line after your connection code:

  1. mysql_query("SET CHARACTER SET utf8");


It may help.

doodlebug
Hi Goran - the extra line made no difference sad.gif
Source code looks ok - everything is UTF-8

dariuszp
Hmmm... if all files, database and website use UTF-8 then i have no idea what's wrong. You can try what goran send you. Anyway, also try something like that:

Kod
$string1 = isset($_POST['firstname']) ? $_POST['firstname'] : false;

if(empty($string1))
{

echo("<h2>Imiê:<font color=red>Prozsê wype³niæ</font></h2>\n");
$showbutton=1;
}
else
{
$firstname = preg_replace ("[^0-9a-zA-Z?±æê³ñó¶¿¼¡ÆÊ£ÑÓ¦¯¬ ]", "", $string1);
$firstname = htmlspecialchars($firstname);
echo("<h2><span class=profile>Imiê:</span> <font color=#04B404>" . $firstname .

"</font></h2>\n");
echo("<input type=hidden name=firstname value=" . $firstname . ">");
Pilsener
Hello. I know problem with local artificial letter and recommended use http://pl2.php.net/manual/en/book.mbstring.php and mb_* function, example for check encoding:
http://pl2.php.net/manual/en/function.mb-detect-encoding.php
Try check encoding from received POST, during insert to db and from db.
mrok
Try use var_dump(variable) in few lines in your code and check if $variable has expected value.
First parameter in preg_replace does not look like correct regex pattern.
To jest wersja lo-fi g³ównej zawarto¶ci. Aby zobaczyæ pe³n± wersjê z wiêksz± zawarto¶ci±, obrazkami i formatowaniem proszê kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.