本文整理汇总了PHP中Encoding::EncodingExists方法的典型用法代码示例。如果您正苦于以下问题:PHP Encoding::EncodingExists方法的具体用法?PHP Encoding::EncodingExists怎么用?PHP Encoding::EncodingExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Encoding
的用法示例。
在下文中一共展示了Encoding::EncodingExists方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new item
*
* @access public
* @return void
*/
public function actionCreate()
{
$this->_checkAuth();
$currentModel = mb_strtolower($_GET['model'], 'UTF-8');
$return_array = array();
$return_custom = false;
switch ($currentModel) {
// Get an instance of the respective model
case 'convert':
$model = new Convert();
break;
default:
$this->_sendResponse(501, sprintf('Mode <b>create</b> is not implemented for model <b>%s</b>', $_GET['model']));
exit;
}
// Try to assign POST values to attributes
foreach ($_POST as $var => $value) {
// Does the model have this attribute?
if ($model->hasAttribute($var)) {
$model->{$var} = $value;
} else {
// No, raise an error
$this->_sendResponse(500, sprintf('Parameter <b>%s</b> is not allowed for model <b>%s</b>', $var, $_GET['model']));
}
}
if ($currentModel == 'convert') {
$model->user_id = $this->user_id;
$return_custom = true;
if ($model->data_encoding != '' && $model->data_encoding != null) {
$model->data_encoding = trim(mb_strtoupper($model->data_encoding, 'UTF-8'));
if (!Encoding::EncodingExists($model->data_encoding)) {
$this->_sendResponse(500, sprintf('Parameter <b>%s</b> is not valid for model <b>%s</b>. Valid values: ' . implode(', ', Encoding::$list), 'data_encoding', $_GET['model']));
}
} else {
$model->data_encoding = null;
}
if ($model->data_encoding != null) {
$model->data = iconv($model->data_encoding, 'UTF-8', $model->data);
}
switch (mb_strtolower($model->data_type, 'UTF-8')) {
case 'json':
if ($model->data != '') {
$list = json_decode($model->data, true);
// check if array is designed as: array( array("###KEY_TO_REPLACE###" => "Replaced value"), array(...))
$keys = array_keys($list);
$keys_ok = true;
for ($i = 0; $i < count($keys); ++$i) {
if (!is_numeric($keys[$i])) {
$keys_ok = false;
}
}
if ($keys_ok) {
$model->data_to_use = base64_encode(serialize($list));
} else {
$this->_sendResponse(500, sprintf('Parameter <b>%s</b> is invalid json format for model <b>%s</b>. JSON structure should be: [{"###KEY_TO_REPLACE###":"Replaced Value 1","###KEY###":"Key 1"},{"###KEY_TO_REPLACE###":"Replaced Value 2","###KEY###":"Key 2"}]', 'data', $_GET['model']));
}
} else {
$model->data_to_use = base64_encode(serialize(array()));
}
break;
case 'csv':
$delimiter = ';';
$enclosure = '"';
if ($model->data_parameters != null && $model->data_parameters != '') {
$params = explode('||', $model->data_parameters);
foreach ($params as $param) {
$param = explode('==', $param);
$key = $param[0];
$value = isset($param[1]) ? $param[1] : '';
switch ($key) {
case 'delimiter':
$delimiter = $value;
break;
case 'enclosure':
$enclosure = $value;
break;
default:
$this->_sendResponse(500, sprintf('Parameter <b>%s</b> is invalid format for model <b>%s</b>. Valid value for CSV is: \'setting1==value||setting2==value\', example: \'delimiter==;||enclosure=="\', default delimiter is: \';\', default enclosure is: \'"\'', 'data_parameters', $_GET['model']));
break;
}
}
}
$data = CSV::toArray($model->data, $delimiter, $enclosure);
if (count($data) > 0) {
if (count($data) > 1) {
$header = $data[0];
$list = array();
for ($i = 1; $i < count($data); ++$i) {
$row = array();
for ($c = 0; $c < count($header); ++$c) {
$row[$header[$c]] = isset($data[$c]) ? $data[$c] : '';
}
$list[] = $row;
}
//.........这里部分代码省略.........