/** * determine if the string is composed only of ascii characters * * @param string $str input string * @param boolean $utf8 attempt utf8 match on failure (default yes) * * @return boolean true if string is ascii * @access public * @static */ function isAscii($str, $utf8 = true) { $str = preg_replace('/\\s+/', '', $str); // eliminate all white space from the string /* FIXME: This is a pretty brutal hack to make utf8 and 8859-1 work. */ /* match low- or high-ascii characters */ if (preg_match('/[\\x00-\\x20]|[\\x7F-\\xFF]/', $str)) { // || // low ascii characters // preg_match( '/[\x7F-\xFF]/', $str ) ) { // high ascii characters if ($utf8) { /* if we did match, try for utf-8, or iso8859-1 */ return CRM_Utils_String::isUtf8($str); } else { return false; } } return true; }