What string encoding does php use?
A PHP string is just a sequence of bytes, with no encoding tagged to it whatsoever. String values can come from various sources: the client (over HTTP), a database, a file, or from string literals in your source code. PHP reads all these as byte sequences, and it never extracts any encoding information. Show As long as all your data sources and destinations use the same encoding, the worst thing that can happen is that string positions are wrong (if you use multi-byte encodings), since PHP will count bytes, not characters. But if the encodings don't match (e.g. you write a string literal in a source file stored as UTF-8, and then send it to a database that expects Latin-1), PHP will not perform any conversion for you: it will happily copy the bytes over raw. The sanest solution is this:
Why UTF-8? Because it can represent all Unicode characters and thus supersedes all the existing 7-bit and 8-bit encodings, and because it is binary compatible with ASCII, that is, every valid ASCII string is also a valid UTF-8 string (but not vv.). In your example, what happens is this. First, you save your source file; your text editor is probably configured to use UTF-8, so your string literal ends up UTF-8 encoded on disk. PHP reads this file, interpreting the string as a series of bytes;
(PHP 4, PHP 5, PHP 7, PHP 8) utf8_encode — Converts a string from ISO-8859-1 to UTF-8 Warning This function has been DEPRECATED as of PHP 8.2.0. Relying on this function is highly discouraged. Descriptionutf8_encode(string
Parametersstring An ISO-8859-1 string. Return Values Returns the UTF-8 translation of Changelog
ExamplesExample #1 Basic example
The above example will output: See Also
deceze at gmail dot com ¶ 11 years ago
Aidan Kehoe 18 years ago
cp1252_to_utf8($str) { bisqwit at iki dot fi ¶ 17 years ago
a dot rueedlinger at gmail dot com ¶ 9 years ago
Oscar Broman ¶ 10 years ago
$value); Pini ¶ 6 years ago
Mark AT modernbill DOT com ¶ 17 years ago
rattones at gmail dot com ¶ 1 year ago
rogeriogirodo at gmail dot com ¶ 13 years ago
powtac 4t gmx d0t de ¶ 11 years ago
mb_check_encoding($content, 'UTF-8')) {
Janci ¶ 16 years ago
$iconv_to != "UTF-8") { Anonymous ¶ 16 years ago
rocketman ¶ 16 years ago
mailing at jcn50 dot com ¶ 16 years ago
Yumok ¶ 11 years ago
www.tricinty.com ¶ 14 years ago
$result; suttichai at ceforce dot com ¶ 17 years ago
hrpeters (at) gmx (dot) net ¶ 17 years ago
Karen ¶ 18 years ago
emze at donazga dot net ¶ 15 years ago
ronen at greyzone dot com ¶ 20 years ago
JF Sebastian ¶ 17 years ago
Net Raven ¶ 18 years ago
Are PHP strings UTFAll PHP string functions work well with UTF-8 encoded strings as long as the strings use only 7-bit ASCII characters (because the encoding of the first 128 characters is identical in ASCII and UTF-8).
What is UTFDefinition and Usage. The utf8_encode() function encodes an ISO-8859-1 string to UTF-8. Unicode is a universal standard, and has been developed to describe all possible characters of all languages plus a lot of symbols with one unique number for each character/symbol.
How strings are used in PHP?We can create a string in PHP by enclosing the text in a single-quote. It is the easiest way to specify string in PHP. For specifying a literal single quote, escape it with a backslash (\) and to specify a literal backslash (\) use double backslash (\\).
What is string and its types in PHP?A string is series of characters, where a character is the same as a byte. This means that PHP only supports a 256-character set, and hence does not offer native Unicode support. See details of the string type. Note: On 32-bit builds, a string can be as large as up to 2GB (2147483647 bytes maximum)
|