473,394 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

character encoding problem - £ (pound) sign

ben
Hi all,

I have a simple PHP page that takes values from a form and puts them in a
database (MySQL).

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
POST)

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 :)

Cheers,

Ben

--

test.php:

<?php
mysql_connect('localhost', 'root', '');
mysql_select_db("test");
mysql_query("INSERT INTO test VALUES('".$_REQUEST['testpound']."')");
?>
<HTML>
<BODY>
<form action="test.php">
<input name="testpound">
<input type="submit">
</form>
</body>
</html>
Oct 27 '05 #1
4 16791
The problem is indeed a character set one.

* 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.

Oct 31 '05 #2
On 31 Oct 2005 08:57:21 -0800, "Ciaran" <ci***********@gmail.com> wrote:
* 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.


It is a far better idea to send a true Content-type header, using header().
--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Oct 31 '05 #3
ben
> It is a far better idea to send a true Content-type header, using
header().


That did it!

Cheers,

Ben
Nov 1 '05 #4
That's a very good point, I got into the habit of using META tags
because I used to just have shared, HTML-only hosting.

I guess there's no harm in doing both.

Nov 1 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Simon Harris | last post by:
Hi All, I have developed an online ordering system, all seems to work fine, apart from pound signs get replaced by question marks. After some research, I have found that this is due to question...
9
by: Joe Blow | last post by:
Strange problem, Web pages encoded in utf-8 are appearing on customers' browsers as iso-western european. This means that characters like the British £ symbol get messed up. No amount of...
7
by: Jim Lawton | last post by:
Hello, tried this in framework.aspnet without any luck so far, maybe someone here has a comment ... TIA, Jim ..net c# httphandler straight html form at browser. GBP pound sign problem (I...
2
by: Jim Lawton | last post by:
Hi, ..net c# httphandler straight html form at browser. GBP pound sign problem (I know I know - I *can* decode it, but I've got to understand what and why I should be doing stuff) I am...
4
by: monomaniac21 | last post by:
hi im outputting text from a db and where a £ sign has been entered a ? character appears instead which i cant seem to get rid of with a simple str_replace. is their a way to get rid of it? and...
5
by: Timothy Madden | last post by:
Hello Is there a function that will allow me to output text written in utf-8 (from db for example) if my document has Content-Type: text/html; charset=ISO-8859-1 I mean htmlspecialchars()...
2
by: withers | last post by:
XML gives an error when I have a £ sign (GBP) - £ - in a string. I've fixed this by converting it to its HTML number. In case other characters may cause the same error, I'm converting characters...
2
by: David Gillen | last post by:
Hello. I've a problem (which I believe is a character encoding problem) where I retrieve data from a MSSQL database and euro and pound sign symbols appear as ? when a do a print_r of the rows...
3
by: tparks69 | last post by:
I'm getting some Chinese language data from sql server in some encoded format, maybe unicode?... it starts with an ampersand '&', then there is a '#' pound sign, then a 5 digit integer, then a semi...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.