5 Answers 5
Try this :
$data['price']='£1';
print_r(json_encode($data));
answered May 14, 2012 at 11:13
Darshit Gajjar
7114 gold badges13 silver badges26 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Ben
shouldn't it be
£1 technically?Darshit Gajjar
@Ben yes, it should be. As i have tried without ';' I got the same result.. so I think it's not necessary :) thnk you tho
You are not encoding same array.. you are storing value in $dat and encoding $data....
check your code ..
answered May 14, 2012 at 11:09
Rukmi Patel
2,5619 gold badges29 silver badges42 bronze badges
1 Comment
Ali
He's getting the print_r correctly so he must've made a typo posting his code here
I am afraid you cannot encode £ to JSON unfortunately.
You can try £ in it's place and it will work.
Ben
21.3k12 gold badges75 silver badges117 bronze badges
answered May 14, 2012 at 11:21
transilvlad
14.6k13 gold badges48 silver badges81 bronze badges
Comments
Try this
$data['price'] = htmlentities('1ドル', ENT_COMPAT, 'utf-8');
Pang
10.2k146 gold badges87 silver badges126 bronze badges
Comments
Try like this:
$data['price']="1ドル";
print_r(json_encode($data));
My result:
{"price":"1ドル"}
4 Comments
Darvex
He wants the pound sign, not dollar sign
Hataru
sure but i don't have pound on my keyboard :)
Ben
@Hataru that's kind of a dumb reply then since $ is on the ascii table and doesn't cause any utf8 json encoding issue..
Hataru
yes i try now with pound and of course he needs £ ... thanks
lang-php
£with£Seems like an