public function testToUTF8() { $actual = ARC2::toUTF8('foo'); $this->assertEquals('foo', $actual); $actual = ARC2::toUTF8(utf8_encode('Iñtërnâtiônàlizætiøn')); $this->assertEquals('Iñtërnâtiônàlizætiøn', $actual); }
function getUTF8Char($v) { $val = $v[1]; if (strlen(trim($val)) === 1) { return utf8_encode($val); } if (preg_match('/^([\\x00-\\x7f])(.+)/', $val, $m)) { return $m[1] . ARC2::toUTF8($m[2]); } return $val; }
function xString($v) { /* largely simplified, may need some tweaks in following revisions */ $sub_v = $v; if (!preg_match('/^\\s*([\']{3}|\'|[\\"]{3}|\\")(.*)$/s', $sub_v, $m)) { return array(0, $v); } $delim = $m[1]; $rest = $m[2]; $sub_types = array("'''" => 'literal_long1', '"""' => 'literal_long2', "'" => 'literal1', '"' => 'literal2'); $sub_type = $sub_types[$delim]; if (preg_match('/^([^\\x5c]*|.*[^\\x5c]|.*\\x5c{2})' . str_replace("'", "\\'", $delim) . '(.*)$/sU', $rest, $m)) { return array(array('value' => ARC2::toUTF8($m[1]), 'type' => 'literal', 'sub_type' => $sub_type), $m[2]); } return array(0, $v); }
function toUTF8($str) { return $this->adjust_utf8 ? ARC2::toUTF8($str) : $str; }
function toUTF8($v) { return $this->adjust_utf8 ? ARC2::toUTF8($v) : $v; }
function getOComp($val) { /* try date (e.g. 21 August 2007) */ if (preg_match('/^[0-9]{1,2}\\s+[a-z]+\\s+[0-9]{4}/i', $val) && ($uts = strtotime($val)) && $uts !== -1) { return date("Y-m-d\\TH:i:s", $uts); } if (preg_match('/^[0-9]{4}[0-9\\-\\:\\T\\Z\\+]+([a-z]{2,3})?$/i', $val)) { return $val; } if (is_numeric($val)) { $val = sprintf("%f", $val); if (preg_match("/([\\-\\+])([0-9]*)\\.([0-9]*)/", $val, $m)) { return $m[1] . sprintf("%018s", $m[2]) . "." . sprintf("%-015s", $m[3]); } if (preg_match("/([0-9]*)\\.([0-9]*)/", $val, $m)) { return "+" . sprintf("%018s", $m[1]) . "." . sprintf("%-015s", $m[2]); } return $val; } /* any other string: remove tags, linebreaks etc. */ $val = substr(trim(preg_replace('/[\\W\\s]+/is', '-', strip_tags($val))), 0, 35); return ARC2::toUTF8($val); }