Hi all,
I have a problem. I have two different pages. Both of them have identical textboxes displaying a variable with special characters in it. One of them displays the special characters correctly, the other one does not. I can’t figure out why.
The value of the variable is “Tester’s Event”, without the double quotes. There is an apostrophe in it.
The line that displays the variable looks like this:
[php]
[/php]
This variable $name is a $_POST variable. The variable initially looks like this:
Tester%27s%20Event - the special characters are my clumsy attempt at stopping apostrophes causing problems.
Before the variable is used in a database query, the following lines are applied to it:
[php]
$name = urldecode($name);
$name = str_replace("’", “’’”, $name);
[/php]
After the query, I would like to display it in my textbox. To prevent errors, I run the following two lines:
[php]
$name = str_replace("’’", “’”, $name);
$name = htmlentities($name, ENT_QUOTES);
[/php]
So in my first page, this line displays my variable no problems. Special characters are converted correctly.
[php]
[/php]
BUT! On my second page, I have an identical logical setup. Special characters are not converting, and the variable is displaying like: Tester's Event and I have no idea why.
The code looks like this:
[php]
[/php]
I tried hard-coding the variable, like this:
[php]
$name = ‘Tester & # 3 9 ; s Event’; (without the spaces in the first word)
[/php]
In that case, the special character converted fine and displayed as ‘Tester’s Event’.
Thanks for your help. I hope I’ve been clear enough.
James.