本文整理汇总了PHP中Ak::utf8方法的典型用法代码示例。如果您正苦于以下问题:PHP Ak::utf8方法的具体用法?PHP Ak::utf8怎么用?PHP Ak::utf8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ak
的用法示例。
在下文中一共展示了Ak::utf8方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toXml
/**
* Generate a xml representation of the model record.
*
* Example result:
*
* <?xml version="1.0" encoding="UTF-8"?>
* <person>
* <id>1</id>
* <first-name>Hansi</first-name>
* <last-name>Müller</last-name>
* <email>hans@mueller.com</email>
* <created-at type="datetime">2008-01-01 13:01:23</created-at>
* </person>
*
* parameters:
*
* @param array $options
*
* option parameters:
* array(
* 'collection' => array($Person1,$Person), // array of ActiveRecords
* 'include' => array('association1','association2'), // include the associations when exporting
* 'exclude' => array('id','name'), // exclude the attribtues
* 'only' => array('email','last_name') // only export these attributes
* )
* @return string in Xml Format
*/
function toXml($options = array())
{
if (is_array($options) && isset($options[0]) && is_a($options[0], 'AkActiveRecord')) {
$options = array('collection'=>$options);
}
if (isset($options['collection']) && is_array($options['collection']) && $options['collection'][0]->_modelName == $this->_modelName) {
$root = strtolower(AkInflector::pluralize($this->_modelName));
$root = $this->_convert_column_to_xml_element($root);
$xml = '';
if (!(isset($options['skip_instruct']) && $options['skip_instruct'] == true)) {
$xml .= '<?xml version="1.0" encoding="UTF-8"?>';
}
$xml .= '<' . $root . '>';
$collection = $options['collection'];
unset($options['collection']);
$options['skip_instruct'] = true;
foreach ($collection as $element) {
$xml .= $element->toXml($options);
}
$xml .= '</' . $root .'>';
return $xml;
}
/**
* see if we need to include associations
*/
$associatedIds = array();
if (isset($options['include']) && !empty($options['include'])) {
$options['include'] = is_array($options['include'])?$options['include']:preg_split('/,\s*/',$options['include']);
foreach ($this->_associations as $key => $obj) {
if (in_array($key,$options['include'])) {
if ($obj->getType()!='hasAndBelongsToMany') {
$associatedIds[$obj->getAssociationId() . '_id'] = array('name'=>$key,'type'=>$obj->getType());
} else {
$associatedIds[$key] = array('name'=>$key,'type'=>$obj->getType());
}
}
}
}
if (isset($options['only'])) {
$options['only'] = is_array($options['only'])?$options['only']:preg_split('/,\s*/',$options['only']);
}
if (isset($options['except'])) {
$options['except'] = is_array($options['except'])?$options['except']:preg_split('/,\s*/',$options['except']);
}
$xml = '';
if (!(isset($options['skip_instruct']) && $options['skip_instruct'] == true)) {
$xml .= '<?xml version="1.0" encoding="UTF-8"?>';
}
$root = $this->_convert_column_to_xml_element(strtolower($this->_modelName));
$xml .= '<' . $root . '>';
$xml .= "\n";
foreach ($this->_columns as $key => $def) {
if (isset($options['except']) && in_array($key, $options['except'])) {
continue;
} else if (isset($options['only']) && !in_array($key, $options['only'])) {
continue;
} else {
$columnType = $def['type'];
$elementName = $this->_convert_column_to_xml_element($key);
$xml .= '<' . $elementName;
$val = $this->$key;
if (!in_array($columnType,array('string','text','serial'))) {
$xml .= ' type="' . $columnType . '"';
if ($columnType=='boolean') $val = $val?1:0;
}
$xml .= '>' . Ak::utf8($val) . '</' . $elementName . '>';
$xml .= "\n";
}
}
if (isset($options['include'])) {
foreach($this->_associationIds as $key=>$val) {
//.........这里部分代码省略.........
示例2: utf8
/**
* Recodes "$text" into utf-8 from "$input_string_encoding"
*/
function utf8($text, $input_string_encoding = null)
{
return Ak::utf8($text, $input_string_encoding);
}
示例3: toXml
//.........这里部分代码省略.........
$xml = '';
if (!(isset($options['skip_instruct']) && $options['skip_instruct'] == true)) {
$xml .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
}
$xml .= $current_padding . '<' . $root . " type=\"array\">\n";
$collection = $options['collection'];
unset($options['collection']);
$options['skip_instruct'] = true;
$options['padding']++;
foreach ($collection as $element) {
$xml .= $element->toXml($options);
}
$xml .= $current_padding . '</' . $root . ">\n";
return $xml;
}
/**
* see if we need to include associations
*/
$associatedIds = array();
if (isset($options['include']) && !empty($options['include'])) {
$options['include'] = is_array($options['include']) ? $options['include'] : preg_split('/,\\s*/', $options['include']);
foreach ($this->_Model->getAssociations() as $key => $obj) {
if (in_array($key, $options['include'])) {
if ($obj->getType() != 'hasAndBelongsToMany') {
$associatedIds[$obj->getAssociationIds() . '_id'] = array('name' => $key, 'type' => $obj->getType());
} else {
$associatedIds[$key] = array('name' => $key, 'type' => $obj->getType());
}
}
}
}
if (isset($options['only'])) {
$options['only'] = is_array($options['only']) ? $options['only'] : preg_split('/,\\s*/', $options['only']);
}
if (isset($options['except'])) {
$options['except'] = is_array($options['except']) ? $options['except'] : preg_split('/,\\s*/', $options['except']);
}
$xml = '';
if (!(isset($options['skip_instruct']) && $options['skip_instruct'] == true)) {
$xml .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
}
$root = $this->_convertColumnToXmlElement(AkInflector::underscore($this->_Model->getModelName()));
$xml .= $current_padding . '<' . $root . ">\n";
foreach ($this->_Model->getColumns() as $key => $def) {
if (isset($options['except']) && in_array($key, $options['except'])) {
continue;
} else {
if (isset($options['only']) && !in_array($key, $options['only'])) {
continue;
} else {
$columnType = $def['type'];
$elementName = $this->_convertColumnToXmlElement($key);
$xml .= $current_padding . ' <' . $elementName;
$val = $this->_Model->{$key};
if (!in_array($columnType, array('string', 'text', 'serial'))) {
$xml .= ' type="' . $columnType . '"';
if ($columnType == 'boolean') {
$val = $val ? 1 : 0;
}
} elseif ($columnType == 'serial' && is_numeric($val)) {
$xml .= ' type="integer"';
}
if (!empty($val) && in_array($columnType, array('datetime'))) {
// UTC (Coordinated Universal Time) http://www.w3.org/TR/NOTE-datetime
$val = gmdate('Y-m-d\\TH:i:s\\Z', Ak::getTimestamp($val));
}
if (is_null($val)) {
$xml .= ' nil="true"';
}
$xml .= '>' . Ak::utf8($val) . '</' . $elementName . ">\n";
}
}
}
if (isset($options['include'])) {
foreach ($this->_Model->getAssociations() as $key => $val) {
if (in_array($key, $options['include']) || in_array($val, $options['include'])) {
if (is_array($this->_Model->{$key})) {
$associationElement = $key;
$associationElement = AkInflector::underscore(AkInflector::pluralize($associationElement));
$associationElement = $this->_convertColumnToXmlElement($associationElement);
$xml .= $current_padding . '<' . $associationElement . " type=\"array\">\n";
$options['padding']++;
foreach ($this->_Model->{$key} as $el) {
if ($el instanceof AkBaseModel) {
$xml .= $el->toXml(array('skip_instruct' => true));
}
}
$xml .= $current_padding . '</' . $associationElement . ">\n";
} else {
$el = $this->_Model->{$key}->load();
if ($el instanceof AkBaseModel) {
$xml .= $el->toXml(array('skip_instruct' => true));
}
}
}
}
}
$xml .= $current_padding . '</' . $root . ">\n";
return $xml;
}