PHP charset and £ sign

Associate
Joined
18 Oct 2002
Posts
2,055
Location
Southend-on-Sea
I'm having a problem extracting data from a Foxpro database and putting it into a PHP array, but only when the data contains a £ sign.

I assign the db value to a php variable and all of the data is fine, including £ signs. However, I then have some code that populates an array and at this point it fails. Any data that contains a £ sign is assigned a null value in the array.

Its obviously something to do with character sets but I'm struggling to work out what the issue is. I'm running XAMPP on a Windows server. The server's locale is set to UK and I've tried setting PHP default charset to both UTF-8 and ISO-8859-1 but neither work.

Can anyone suggest a solution? I rarely have to deal with character sets so not sure where I should be heading.

Thanks
 
Can you replace it with £ ?

No, if I try and do anything with the data after assigning it to a variable it just returns a null value.

is the database character set utf-8?

Not sure tbh. Its a Foxpro db that's part of a software suite but I can't seem to find what charset it uses.

What I have noticed is that if I use ISO-8859-1 as the default charset the £ sign gets extracted from the DB and I can assign to a variable without issue. However, if I set it to UTF-8 then the £ sign turns into � as soon as I assign it to a variable.
 
OK, seems putting the value into the array is not causing the issue as I can display the entire array, including £ signs. However, the output from the script is a JSON file and this seems to be where its failing.

The code I'm using to encode the json is:

PHP:
$json_object = array("aaData" => $results);
echo json_encode($json_object);

Is there a reason why this won't accept data with a £ sign?

edit - OK, seem to be answering my own question. Seems json_encode only works with UTF-8 so guess that's why its not working.
 
Last edited:
For anyone that's interested, I resolved the issue by utf8 encoding the array variable:

PHP:
$results[$i][8] = utf8_encode($f9->value);

This then allows the json_encode to work correctly.
 
Back
Top Bottom