473,804 Members | 4,181 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("IN SERT 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("IN SERT INTO test VALUES('".$_REQ UEST['testpound']."')");
?>
<HTML>
<BODY>
<form action="test.ph p">
<input name="testpound ">
<input type="submit">
</form>
</body>
</html>
Oct 27 '05 #1
4 16813
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.u k :: 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
1262
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 mark being in the extended asccii character set, and have been advised to use UNICODE or HTML. HTML is not an option (We currently use plain text), as we have some clients that use non HTML capable email software (Yes, they're still about!)
9
5798
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 tinkering with browser settings or the server settings has helped. Any ideas what the root of the problem might be? The page in question is www.itchy-coo.com (displays fine on my browser, and other North American browsers, seemingly). I'd appreciate...
7
2541
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 know I know - I *can* decode it, but I've got to
2
2636
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 uploading text data from a form. This data is either directly input into a textarea, or is a file stream originating from a .txt file, (or other basic text file (like off Mac or Unix - of course I don't necessarily know at present it's
4
14003
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 what is causing it? regards marc
5
4899
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() and htmlentities() will only convert characters that have an associated entity defined in HTML.
2
2467
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 to their HTML numbers that < 32 or 126 decimal. Is this correct? What would you advise? Thanking you in anticipation.
2
4807
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 immediately after retrieving them from the database. The data can be seen correctly in the SQL manager program. I connect to the database using the PEAR DB library. Has anyone encountered this problem and/or know of a solution. Thanks, David.
3
5036
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 colon. I notice it gets translated when I post it exactly, so I'm trying to descibe it here. If I put some spaces between it, a single character looks like this (remove spaces): & # 35843 ; Anyway, THIS is the big problem: 1. In ASP.NET...
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10575
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10330
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10319
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3816
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.