/** * Split a string into an array of individual characters * The function will look at $this->nativeCharset and if that is set, the input string is expected to be UTF-8 encoded, possibly with entities in it. Otherwise the string is supposed to be a single-byte charset which is just splitted by a for-loop. * * @param string The text string to split * @param boolean Return Unicode numbers instead of chars. * @return array Numerical array with a char as each value. */ function singleChars($theText, $returnUnicodeNumber = FALSE) { if ($this->nativeCharset) { return $this->csConvObj->utf8_to_numberarray($theText, 1, $returnUnicodeNumber ? 0 : 1); // Get an array of separated UTF-8 chars } else { $output = array(); $c = strlen($theText); for ($a = 0; $a < $c; $a++) { $output[] = substr($theText, $a, 1); } return $output; } }
/** * Converts the input string to a JavaScript function returning the same string, but charset-safe. * Used for confirm and alert boxes where we must make sure that any string content * does not break the script AND want to make sure the charset is preserved. * Originally I used the JS function unescape() in combination with PHP function * rawurlencode() in order to pass strings in a safe way. This could still be done * for iso-8859-1 charsets but now I have applied the same method here for all charsets. * * @param string Input string, encoded with $this->charSet * @return string Output string, a JavaScript function: "String.fromCharCode(......)" * @access public */ public function JScharCode($str) { // Convert string to UTF-8: if ($this->charSet != 'utf-8') { $str = $this->csConvObj->utf8_encode($str, $this->charSet); } // Convert the UTF-8 string into a array of char numbers: $nArr = $this->csConvObj->utf8_to_numberarray($str); return 'String.fromCharCode(' . implode(',', $nArr) . ')'; }