Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- character encoding problem - £ (pound) sign
October 27, 2005, 12:54 pm
rate this thread
I have a simple PHP page that takes values from a form and puts them in a
The code is in a file test.php, which I have typed in at the bottom of
this post (please excuse any typos). This page is not a production page -
I created it just to try and solve the £ sign problem I am having.
When I put the pound sign (£) into the input box and submit the form,
what gets inserted into mysql is an A with a ^ on top, followed by the
pound sign. I notice that the request URI shows the £ sign as %C2%A3. If
I run the query manually in php (i.e. mysql_query("INSERT INTO test
VALUES('£')") ) then it is fine. (The problem occurs with both GET and
I have read up a bit about it and I believe that the problem is that one
part of the system uses UTF-8 while the other part uses ISO-8859-1. The
database is ISO-8859-1 (latin1).
Using phpmyadmin, I can put a £ sign into the database with no problem,
so I know that there must be a solution to this issue within PHP, but I
have no idea what it is!!!!
Any clues appreciated :)
mysql_connect('localhost', 'root', '');
mysql_query("INSERT INTO test VALUES('".$_REQUEST['testpound']."')");
Re: character encoding problem - £ (pound) sign
* Firstly, you need to have a HEAD element in your HTML. HEAD and
TITLE are not optional. This isn't really part of the problem though.
* Secondly, you should put the following in your HEAD:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"
This will tell user agents what charset the page is being presented in,
rather than them having to guess. In the majority of cases this will
also govern which character set the form submission takes place in.
It's always a good idea to specify your charset in the page.