当前位置: 首页>>代码示例>>PHP>>正文


PHP Json::htmlEncode方法代码示例

本文整理汇总了PHP中Json::htmlEncode方法的典型用法代码示例。如果您正苦于以下问题:PHP Json::htmlEncode方法的具体用法?PHP Json::htmlEncode怎么用?PHP Json::htmlEncode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Json的用法示例。


在下文中一共展示了Json::htmlEncode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: renderTagAttributes

 /**
  * Renders the HTML tag attributes.
  *
  * Attributes whose values are of boolean type will be treated as
  * [boolean attributes](http://www.w3.org/TR/html5/infrastructure.html#boolean-attributes).
  *
  * Attributes whose values are null will not be rendered.
  *
  * The values of attributes will be HTML-encoded using [[encode()]].
  *
  * The "data" attribute is specially handled when it is receiving an array value. In this case,
  * the array will be "expanded" and a list data attributes will be rendered. For example,
  * if `'data' => ['id' => 1, 'name' => 'leaps']`, then this will be rendered:
  * `data-id="1" data-name="leaps"`.
  * Additionally `'data' => ['params' => ['id' => 1, 'name' => 'leaps'], 'status' => 'ok']` will be rendered as:
  * `data-params='{"id":1,"name":"leaps"}' data-status="ok"`.
  *
  * @param array $attributes attributes to be rendered. The attribute values will be HTML-encoded using [[encode()]].
  * @return string the rendering result. If the attributes are not empty, they will be rendered
  * into a string with a leading white space (so that it can be directly appended to the tag name
  * in a tag. If there is no attribute, an empty string will be returned.
  */
 public static function renderTagAttributes($attributes)
 {
     if (count($attributes) > 1) {
         $sorted = [];
         foreach (static::$attributeOrder as $name) {
             if (isset($attributes[$name])) {
                 $sorted[$name] = $attributes[$name];
             }
         }
         $attributes = array_merge($sorted, $attributes);
     }
     $html = '';
     foreach ($attributes as $name => $value) {
         if (is_bool($value)) {
             if ($value) {
                 $html .= " {$name}";
             }
         } elseif (is_array($value)) {
             if (in_array($name, static::$dataAttributes)) {
                 foreach ($value as $n => $v) {
                     if (is_array($v)) {
                         $html .= " {$name}-{$n}='" . Json::htmlEncode($v) . "'";
                     } else {
                         $html .= " {$name}-{$n}=\"" . static::encode($v) . '"';
                     }
                 }
             } elseif ($name === 'class') {
                 if (empty($value)) {
                     continue;
                 }
                 $html .= " {$name}=\"" . static::encode(implode(' ', $value)) . '"';
             } elseif ($name === 'style') {
                 if (empty($value)) {
                     continue;
                 }
                 $html .= " {$name}=\"" . static::encode(static::cssStyleFromArray($value)) . '"';
             } else {
                 $html .= " {$name}='" . Json::htmlEncode($value) . "'";
             }
         } elseif ($value !== null) {
             $html .= " {$name}=\"" . static::encode($value) . '"';
         }
     }
     return $html;
 }
开发者ID:smallmirror62,项目名称:framework,代码行数:67,代码来源:BaseHtml.php


注:本文中的Json::htmlEncode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。