views:

35

answers:

3

Hey guys,

I am retrieving a variable that contains a £ sign from another page. I want to remove this and I have tried using str_replace but I am left with the following:

�100.

$amount = str_replace('£', '', $amount);

Any ideas?

+1  A: 

If you are guaranteed that the string will always be of that form, chop off the first character.

Alternately, convert it to HTML entities (try htmlentities()) and then do a str_replace().

Kalium
Thanks for your help
Keith Donegan
+2  A: 
  1. try utf8_decode()ing the $amount (or the entire page you received) first
  2. doubt you'll need a 2.
nathan
Bingo! Never used utf8_decode() before, thanks!
Keith Donegan
Np, just remember that only works because that page is UTF-8 encoded, won't work for 'every page on the web'
nathan
A: 

Make sure the character set you're using in your HTML page is the same as the character set your database table is using (and storing data). This usually happens when you have differing character sets.

Also try encoding pound symbols as its HTML entity equivalent (£) before saving them to the database.

Martin Bean