I am slowly getting to grips with a LAMP system (Linux, Apache2, MySQL and PHP), but am having trouble getting the "£" symbol onto the webpage.
When I use the "£", it outputs "A£" (A has a circumflex above it). I read that one uses the "\" escape symbol with "$", to output the "$" character, so I tried that with the "£" character, but it made no difference.
What do I need to do to get the "£" on screen?
-
- Posts: 45
- Joined: Wed Aug 08, 2012 8:05 am
- Location: Gower, Swansea
Re: Outputing a £ Symbol in PHP
Use standard HTML character encodings
£ for £
& for &
Look up HTML characters there are lots of them
½ for 1/2
£ for £
& for &
Look up HTML characters there are lots of them
½ for 1/2
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/
or http://www.pcserviceselectronics.co.uk/pi/
Re: Outputing a £ Symbol in PHP
This means that the server is using UTF-8 encoding, where the pound is encoded as two bytes: 0xC2 0xA3, but the browser is expecting single-byte ISO-8859-1 encoding, where 0xC2 is  and 0xA3 is £.SwanseaMick wrote:When I use the "£", it outputs "A£" (A has a circumflex above it).
You should be able to override the browser encoding in the menus (View→Character Encoding in firefox/iceweasel, Tools→Encoding in chrome/chromium). But the correct solution is to ensure that the page has the correct HTTP header: "Content-type: text/html; charset=UTF-8" or http-equiv.
-
- Posts: 45
- Joined: Wed Aug 08, 2012 8:05 am
- Location: Gower, Swansea
Re: Outputing a £ Symbol in PHP
jojopi,
That did the trick!
Many thanks
That did the trick!
Many thanks
-
- Posts: 45
- Joined: Wed Aug 08, 2012 8:05 am
- Location: Gower, Swansea
Re: Outputing a £ Symbol in PHP
Further to my previous posts, I discovered a drawback in getting MySQL to include the £ in the returned result! Although the resulting page looks 'pretty', one cannot sum the different results to get a grand total, as the individual totals are regarded as strings, and the sum of their results is '0' (zero)!
Goes to show, some you win, some you lose!
Goes to show, some you win, some you lose!
Re: Outputing a £ Symbol in PHP
Its always best to represent things as their "natural" data types, so currency should be a decimal, a yes/no choice would be a tinyint (effectively a boolean) and do all your formatting in the output layer. A String is really a very generic type and while you can manipulate them in a lot of ways its not a suitable way to store numeric data. The other problem is that its bad programming practice where you should be trying to separate the data, logic and presentation layers. So in this case your data is in MySQL and the logic and presentation are in PHP. However in that PHP you should have the logic in a different class to your HTML. This lets you in the future switch things around more easily.SwanseaMick wrote:Further to my previous posts, I discovered a drawback in getting MySQL to include the £ in the returned result! Although the resulting page looks 'pretty', one cannot sum the different results to get a grand total, as the individual totals are regarded as strings, and the sum of their results is '0' (zero)!
Goes to show, some you win, some you lose!
In your case you found you wanted to do some sums on your data that you can't do easily with it as a string. An example that I've just come across was I was trying to get my Pi to output data to a 16x2 display however it wasn't working. I had a suspicion it was due to the slow GPIO library I was using thankfully though I had used interfaces to give me some separation and so to use a new library I just wrote one new file for the new library and changed a couple of words and I was up and running with the new interface that worked. If I hadn't then I would of had to rewrite all my bits of code in all my classes that used the GPIO.
-
- Posts: 45
- Joined: Wed Aug 08, 2012 8:05 am
- Location: Gower, Swansea
Re: Outputing a £ Symbol in PHP
Fruitloaf,
Without sounding tetchy, I am fully aware of the difference between strings and numerical data types.
The point I was trying to make, was that in order to get a 'pretty' output, by using CONCAT & FORMAT in my SQL to get MySQL, I effectively turned numerical data into strings.
My last post was to highlight to others, the unforeseen consequences of these actions.
I didn't want unnecesary £'s on my page, so I took the easy root to eliminate them. I guess I'll now have to go the extra mile and add extra coding to check for value of returns before adding the £, as and where necessary.
Without sounding tetchy, I am fully aware of the difference between strings and numerical data types.
The point I was trying to make, was that in order to get a 'pretty' output, by using CONCAT & FORMAT in my SQL to get MySQL, I effectively turned numerical data into strings.
My last post was to highlight to others, the unforeseen consequences of these actions.
I didn't want unnecesary £'s on my page, so I took the easy root to eliminate them. I guess I'll now have to go the extra mile and add extra coding to check for value of returns before adding the £, as and where necessary.
Re: Outputing a £ Symbol in PHP
Yes you can do a lot of things in MySQL and any SQL it is more a matter of whether they should be there for efficiency. Formatted string in PHP or half hard coded in your presentation layer HTML would be easier and faster.SwanseaMick wrote:Fruitloaf,
Without sounding tetchy, I am fully aware of the difference between strings and numerical data types.
The point I was trying to make, was that in order to get a 'pretty' output, by using CONCAT & FORMAT in my SQL to get MySQL, I effectively turned numerical data into strings.
My last post was to highlight to others, the unforeseen consequences of these actions.
I didn't want unnecesary £'s on my page, so I took the easy root to eliminate them. I guess I'll now have to go the extra mile and add extra coding to check for value of returns before adding the £, as and where necessary.
Unless you are doing multi-currecy, then back to PHP code before you do any HTML outputting,
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/
or http://www.pcserviceselectronics.co.uk/pi/