Jump to content

Recommended Posts

like i know php doesn't like UTF-8.. so if the data in the mysql database is in UTF-8 will that mess stuff up?

 

 

No, UTF-8 data will be fine as long as you don't do any non-binary or non-UTF-8 safe operations on it.

 

 

When ever a variable holds something, PHP is pretty good about storing the value as expected and leaving it alone regardless of the data.

 

 

If you want to use functions on the data or something though, you'll have to make sure the function is multibyte safe.  For example, instead of strlen, you would have to use mb_strlen.

 

 

As for outputting, you'll have to make sure that the client knows it's UTF-8 by the way.  Usually something like the following works fine:

 

header("Content-Type: text/html; charset=UTF-8");

Link to comment
https://forums.phpfreaks.com/topic/176906-php-charset/#findComment-932760
Share on other sites

Hrmmm, kind of.  In PHP 6, I want to think that the default charset PHP uses is the one that the source file is in, but I don't think it really matters much.

 

 

Also, when saving source files in UTF-8, you have to be careful to save without BOM or the PHP engine stutters a bit.

 

 

 

The important part is making sure not to manipulate the data with a function that is not designed to handle that charset, and making sure the web browser knows what charset it is.

Link to comment
https://forums.phpfreaks.com/topic/176906-php-charset/#findComment-932763
Share on other sites

Well, I really don't understand the whole byte things and stuff.... i hate character sets and wish i didn't have to work with them... all i know how to do is write html,css,javascript,php,mysql.. then like 4 days ago i was trying to figure out how to setup my character sets for my files/mysql data... btw is the mysql server only made to understand UTF-8 because thats what my mysql server charset is set for

 

Basiclly, I program php/mysql sites for simple database driven web sites.. i don't work with bytes... just simple stuff.. so what should I save my .php files as and what character collation should i use for all my tables... and can you explain a bit about character sets and bytes or w/e.. i googled it a bit but i don't understand what i found that well.

Link to comment
https://forums.phpfreaks.com/topic/176906-php-charset/#findComment-932766
Share on other sites

A character set is essentially a way for a computer to know how to display stored strings.

 

http://www.w3.org/International/questions/qa-what-is-encoding

 

Explains it fairly well.

 

 

There's a link I saw a while back that explains it really well, but I can't find it.  If you need more info, I'll try to find it for you.

 

 

 

Edit:  Oh, by the way, as to which charset to use, you need to use which ever one can store all of the data you want to store.

 

 

For example, ASCII is only 1 bytes (8 bits), so it can only hold 255 characters.  So ASCII and any charset that uses ASCII (for example, "US-ASCII") is pretty much only good for English.

 

UTF-8 on the other hand is expandable.  It has only 7 bits available for use, but that's because the last bit of the byte is reserved to mark whether the next byte is the same character or a different one.

 

In other words, UTF-8 can expand.  It can have between 1 and 4 bytes, meaning it can have up to 2^(7*4) characters (about 250 million).

Link to comment
https://forums.phpfreaks.com/topic/176906-php-charset/#findComment-932773
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.