/    Sign up×
Community /Pin to ProfileBookmark

UTF8 comparing with MySQL

Hi Folks,

I have a database where the fields are stored in UTF8 and utf_general_ci. I’m pulling the data from the database and I then want to see if a pulled value is in a fixed array which I’ve coded into php (array(“home”,”Über
uns”,”strona główna”)).

For some reason this doesn’t seem to work. I’ve tried setting the Internal/External/Output character encodings and played with other settings, including utf8_en/decoding it as well. Even though in text, the value from MySQL reads “strona główna” (which I believe means Home page in Polish) it doesn’t get found with in_array.

Any help would be great.

Thanks

A

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiDec 23.2009 — Are you running a SET NAMES query before querying for the data?

SET NAMES 'utf8'

Are you also making sure your IDE is saving the source code as utf-8?
Copy linkTweet thisAlerts:
@Ukuser28authorDec 24.2009 — Hi,

I am using SET NAMES so the data should be coming out as UTF8 but it won't compare with the array. I'm not sure if I need to set something in PHP to make my array get read as fully UTF8 - even if the characters themselves are UTF8?

Thanks

A
Copy linkTweet thisAlerts:
@MindzaiDec 24.2009 — If the array is hard coded, and your IDE is using UTF-8, then I can't see any reason why it wouldn't compare. I just ran a test and it worked fine for me. All I can think of is that your IDE is using something other than UTF-8.
Copy linkTweet thisAlerts:
@Ukuser28authorDec 24.2009 — Thank you for that help!!! That fixed it. I'm using PSPad and had obviously not encoded the actual PHP file correctly! Simple but annoying as I've not really used international codings before.

A
×

Success!

Help @Ukuser28 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.3,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...