JustinK101 Posted April 18, 2008 Share Posted April 18, 2008 Can I store special characters such as Arabic and other language symbols in a standard array defined as: $my_array = array(); Do I have to define it as UTF-8? Quote Link to comment https://forums.phpfreaks.com/topic/101648-storing-special-characters-in-an-array/ Share on other sites More sharing options...
effigy Posted April 18, 2008 Share Posted April 18, 2008 What are you using this for? If you're using regular expressions you can use the block ranges and/or properties to do this. An arraying example is here. Quote Link to comment https://forums.phpfreaks.com/topic/101648-storing-special-characters-in-an-array/#findComment-520397 Share on other sites More sharing options...
JustinK101 Posted April 18, 2008 Author Share Posted April 18, 2008 Just storing text strings, but the array is going to be used for locization, so say I want to store spanish characters or other language special characters, such as Arabic and Japanese characters in the array am I going to have problems? Quote Link to comment https://forums.phpfreaks.com/topic/101648-storing-special-characters-in-an-array/#findComment-520747 Share on other sites More sharing options...
effigy Posted April 23, 2008 Share Posted April 23, 2008 Not if they're all stored with the same encoding or you include some metadata about each character's encoding. Quote Link to comment https://forums.phpfreaks.com/topic/101648-storing-special-characters-in-an-array/#findComment-525444 Share on other sites More sharing options...
JustinK101 Posted April 24, 2008 Author Share Posted April 24, 2008 That is what I am asking, do I have to define the encoding type for the array, I am using utf8 for all my columns in my database. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/101648-storing-special-characters-in-an-array/#findComment-525691 Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 Define the encoding, and read up on PHP unicode functions. Quote Link to comment https://forums.phpfreaks.com/topic/101648-storing-special-characters-in-an-array/#findComment-525694 Share on other sites More sharing options...
JustinK101 Posted April 24, 2008 Author Share Posted April 24, 2008 How do I define the encoding? Reading the doc you linked to, only seems to exist in php6, I am running php5. Quote Link to comment https://forums.phpfreaks.com/topic/101648-storing-special-characters-in-an-array/#findComment-525741 Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 Yeah, Unicode support was GREATLY increased in PHP 6. =/ Do some google searches on "php 5 unicode" and see what you can find. Quote Link to comment https://forums.phpfreaks.com/topic/101648-storing-special-characters-in-an-array/#findComment-525745 Share on other sites More sharing options...
JustinK101 Posted April 24, 2008 Author Share Posted April 24, 2008 So any idea what happens if you try and put a standard Janpanse character/gylf in a php5 array as a string? Quote Link to comment https://forums.phpfreaks.com/topic/101648-storing-special-characters-in-an-array/#findComment-525755 Share on other sites More sharing options...
effigy Posted April 24, 2008 Share Posted April 24, 2008 Characters are just representations of numbers and you can store numbers anywhere. It's how these numbers are interpreted that determines the outcome. Therefore, if you're using UTF-8 on your page, store the characters in UTF-8. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <pre> <?php $chars = array( pack('C*', 0xe2, 0x80, 0x94), ### Em dash pack('C*', 0xe2, 0x84, 0xa2), ### Trade mark ); print_r($chars); ?> </pre> Quote Link to comment https://forums.phpfreaks.com/topic/101648-storing-special-characters-in-an-array/#findComment-526050 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.