diff --git a/reference/strings/functions/chr.xml b/reference/strings/functions/chr.xml index b372532f86..563433a1b2 100644 --- a/reference/strings/functions/chr.xml +++ b/reference/strings/functions/chr.xml @@ -3,18 +3,21 @@ chr - Return a specific character + Generate a single-byte string from a number &reftitle.description; stringchr - intascii + intbytevalue Returns a one-character string containing the character specified - by ascii. + by interpreting bytevalue as an unsigned integer. + + + This can be used to create a one-character string in a single-byte encoding such as ASCII, ISO-8859, or Windows 1252, by passing the position of a desired character in the encoding's mapping table. However, note that this function is not aware of any string encoding, and in particular cannot be passed a Unicode code point value to generate a string in a multibyte encoding like UTF-8 or UTF-16. This function complements ord. @@ -26,20 +29,20 @@ - ascii + bytevalue - The extended ASCII code. + An integer between 0 and 255. Values outside the valid range (0..255) will be bitwise and'ed with 255, which is equivalent to the following algorithm: @@ -52,7 +55,7 @@ $ascii %= 256; &reftitle.returnvalues; - Returns the specified character. + A single-character string containing the specified byte. @@ -63,6 +66,8 @@ $ascii %= 256; + + + Building a UTF-8 string from individual bytes + + +]]> + + &example.outputs; + +🐘 + + + diff --git a/reference/strings/functions/ord.xml b/reference/strings/functions/ord.xml index 6fd1841ebf..53766b7a85 100644 --- a/reference/strings/functions/ord.xml +++ b/reference/strings/functions/ord.xml @@ -3,7 +3,7 @@ ord - Return ASCII value of character + Convert the first byte of a string to a value between 0 and 255 @@ -13,8 +13,11 @@ stringstring - Returns the ASCII value of the first character of - string. + Interprets the binary value of the first byte of + string as an unsigned integer between 0 and 255. + + + If the string is in a single-byte encoding, such as ASCII, ISO-8859, or Windows 1252, this is equivalent to returning the position of a character in the character set's mapping table. However, note that this function is not aware of any string encoding, and in particular will never identify a Unicode code point in a multi-byte encoding such as UTF-8 or UTF-16. This function complements chr. @@ -40,7 +43,7 @@ &reftitle.returnvalues; - Returns the ASCII value as an integer. + An integer between 0 and 255. @@ -59,7 +62,31 @@ if (ord($str) == 10) { ?> ]]> - + + + + + Examining the individual bytes of a UTF-8 string + + +]]> + + &example.outputs; + +Byte 0 of $str has value 240 +Byte 1 of $str has value 159 +Byte 2 of $str has value 144 +Byte 3 of $str has value 152 + +