Hello,

I'm having trouble trying to display the pound sterling (£) symbol in a pdf document I create using the fpdf class from http://www.fpdf.org.

When I view the pdf any £ symbol is preceded by a 'Â' and I cannot work out or find a way to just display the simple '£' sign. The nearest I have come to finding anything that covers this problem is here :
http://fyneworks.blogspot.com/2008/06/british-pound-sign-encoding-revisited.html

However it doesn't seem to work or I just don't understand it..

Anyone have any suggestions ?

    How are you adding the character?

    Post some code.

      Kudose;10888015 wrote:

      How are you adding the character?

      Post some code.

      Well as I say I am using the the 'fpdf.php' class available from http://www.fpdf.org and then using the class extension 'mc_table.php' available on the same website here : http://www.fpdf.org/en/script/script12.php

      The class PDF_MC_Table has the method Row() which simply adds an array of data into a pdf as a table row. All the string data is handled via variables, (this is because the data was originally harvested from a website and is in a web-safe format i.e. the pound sign is encoded as '£' and is saved as such in MySQL). It is not until that data is to be displayed in the PDF would I like it changed to the actual £ and I have tried doing so with str_replace :

      $d['price'] = str_replace('£',"£",$d['price']);

      this is where it all then seems to go wrong ! I'm not sure if it's a PHP encoding quirk or the way PDF interprets the £

        Have you tried letting the class figure out how to handle the web safe pound symbol? Have you tried &# 163; ?

        I highly doubt that there is any problem with PHP's support for the pound symbol and find it more likely the issue lies with the class you are using (not that I am saying there is or isn't anything wrong with either).

          6 months later

          I found this thread while trying to solve the same problem. I also am using UTF-8 files, and finding that FPDF assumes latin1, hence the problem.

          For the pound sign, I cam up with:

          substr('£', 1, 1)

          This takes advantage of the fact that substr works on bytes not characters, and the UTF-8 pound sign in my code above has its second byte equivalent to the single byte latin1 pound sign.

          It has the advantage over the iconv solution mentioned elsewhere in that it doesn't require an extension enabling.

          -- Tim.

            [man]utf8_decode[/man] doesn't require an additional extension either.

              Thanks Weedpacket, hadn't come across that function before.

              cheers,
              Tim.

                Write a Reply...