/    Sign up×
Community /Pin to ProfileBookmark

Charset and utf8_decode

Hi

I’ve never paid much attention to encoding or charsets, and I’m pretty sure I do not understand its workings 100% ?
I’ve always just gone with the default in php and mysql, which is iso-8859-1.

But now there’s an external server which apparantly is posting to some of my scripts in utf8. So the data looks pretty strange both on the webpage (page itself is utf8) when showing the post variables and in the database.

I was thinking I would loop through all post-vars and just do a utf_decode on them, since my own server is still posting with iso-8859-1 as I understand. I have a file that is included on all such scripts, and I just thought I’d add something there to decode the data. Maybe like this:

[code=php]
foreach ($_POST as $name=>$value){
$_POST[$name] = utf8_decode($value);
}
[/code]

I’m not sure if that is the best way of doing this. I do not have to do this if the posted variables aren’t in utf8, so is there any way of detecting the encoding first?

Please advice

Thanks
Lubox

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiJun 04.2009 — mb_detect_encoding() is what you're looking for I think. Why is your page utf8 when the database is using iso 8859 though? Wouldn't it be best to stick to one encoding?
×

Success!

Help @Lubox spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...