本文整理汇总了PHP中Encoding::is_utf8方法的典型用法代码示例。如果您正苦于以下问题:PHP Encoding::is_utf8方法的具体用法?PHP Encoding::is_utf8怎么用?PHP Encoding::is_utf8使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Encoding
的用法示例。
在下文中一共展示了Encoding::is_utf8方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: read_object
/**
* Read the next object from the resource. In this case, the 'row' is the
* row in the csv file, and 'line' returns the line number in the file that
* the object STARTED on. (CSV objects may span multiple lines, if they
* contain newlines).
*
* @return array|false
*/
protected function read_object()
{
$obj = fgetcsv($this->csv_fp, null, $this->csv_delim, $this->csv_encl);
$num = $this->line_num;
if (!$obj) {
return false;
} else {
// optionally remove the last, probably blank, column
if (count($obj) && $this->lastcol_skip) {
array_pop($obj);
}
// Increment line number, including any newlines in the object.
// Also check for UTF-8 encoding
$this->line_num++;
foreach ($obj as $i => $col) {
$this->line_num += substr_count($col, "\n");
if (!Encoding::is_utf8($col)) {
$obj[$i] = Encoding::convert_to_utf8($col);
}
}
return array('row' => $this->position + ($this->csv_skip ? 2 : 1), 'data' => $obj, 'line' => $num);
}
}
示例2: air2_model_prevalidate
/**
*
*
* @param unknown $model
*/
function air2_model_prevalidate(&$model)
{
$table = $model->getTable();
$col_defs = $table->getColumns();
$now = air2_date();
foreach ($col_defs as $col => $def) {
if (preg_match('/_uuid$/', $col) && isset($def['unique']) && $def['unique']) {
if (!isset($model->{$col}) || !strlen($model->{$col})) {
$model->{$col} = air2_generate_uuid(12);
}
} elseif (preg_match('/_cre_dtim$/', $col)) {
if (!$model->exists() && !strlen($model->{$col})) {
$model->{$col} = $now;
}
} elseif (preg_match('/_upd_dtim$/', $col)) {
$model->{$col} = $now;
} elseif (preg_match('/_cre_user$/', $col)) {
if (!$model->exists() && !strlen($model->{$col})) {
if (defined('AIR2_REMOTE_USER_ID')) {
$model->{$col} = AIR2_REMOTE_USER_ID;
} else {
$model->{$col} = 1;
//sysuser -- TODO: check for shell users
}
}
} elseif (preg_match('/_upd_user$/', $col)) {
if (defined('AIR2_REMOTE_USER_ID')) {
$model->{$col} = AIR2_REMOTE_USER_ID;
} else {
$model->{$col} = 1;
//sysuser -- TODO: check for shell users
}
} elseif ($def['type'] === 'timestamp') {
// validate the string for non cre/upd timestamps
if (isset($model->{$col}) && !is_null($model->{$col})) {
//NOTE: whenever you set a column in Doctrine, it checks that
//the value has changed. Since '2010-01-01 01:01:01' is equal
//to '2010-01-01T01:01:01', we need to NULL it first
if (strpos($model->{$col}, 'T') !== false) {
$airformat = air2_date(strtotime($model->{$col}));
$model->{$col} = null;
$model->{$col} = $airformat;
}
}
} elseif ($def['type'] === 'date') {
// validate the string for non cre/upd timestamps
if (isset($model->{$col}) && !is_null($model->{$col})) {
//NOTE: whenever you set a column in Doctrine, it checks that
//the value has changed. Since '2010-01-01 01:01:01' is equal
//to '2010-01-01T01:01:01', we need to NULL it first
if (strpos($model->{$col}, 'T') !== false) {
$airformat = air2_date(strtotime($model->{$col}));
$model->{$col} = null;
$model->{$col} = $airformat;
}
}
}
// default values
if (strlen($table->getDefaultValueOf($col)) && !strlen($model->{$col})) {
$model->{$col} = $table->getDefaultValueOf($col);
}
// lastly, check strings for valid UTF8 chars
if ($def['type'] === 'string' && !Encoding::is_utf8($model->{$col})) {
$modelname = get_class($model);
throw new Doctrine_Exception("non-UTF8 string found in {$modelname}->{$col}: " . $model->{$col});
}
}
}
示例3: convert_to_utf8
/**
* Convert non-UTF8 strings to UTF8. Strings already in UTF8 will be
* returned intact.
*
* @param string $str
* @return string
*/
public static function convert_to_utf8($str)
{
if (Encoding::is_ascii($str)) {
// valid! nothing to do
} elseif (Encoding::is_utf8($str)) {
// valid! nothing to do
} elseif (Encoding::is_cp1252($str)) {
$str = utf8_encode($str);
$str = Encoding::fix_cp1252_codepoints_in_utf8($str);
} elseif (Encoding::is_latin1($str)) {
$str = utf8_encode($str);
}
return $str;
}