character encoding problem - £ (pound) sign

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ben

    #1

    character encoding problem - £ (pound) sign

    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>
  • Ciaran

    #2
    Re: character encoding problem - £ (pound) sign

    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.

    Comment

    • Andy Hassall

      #3
      Re: character encoding problem - £ (pound) sign

      On 31 Oct 2005 08:57:21 -0800, "Ciaran" <ciaranmcnulty@ gmail.com> wrote:
      [color=blue]
      >* 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.[/color]

      It is a far better idea to send a true Content-type header, using header().
      --
      Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
      http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

      Comment

      • ben

        #4
        Re: character encoding problem - £ (pound) sign

        > It is a far better idea to send a true Content-type header, using[color=blue]
        > header().[/color]

        That did it!

        Cheers,

        Ben

        Comment

        • Ciaran

          #5
          Re: character encoding problem - £ (pound) sign

          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.

          Comment

          Working...