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


PHP XML_Util::createComment方法代码示例

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


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

示例1: htmlentities

 * creating an end element
 */
print "creating an end element:<br>";
print htmlentities(XML_Util::createEndElement("myNs:myTag"));
print "\n<br><br>\n";
/**
 * creating a CData section
 */
print "creating a CData section:<br>";
print htmlentities(XML_Util::createCDataSection("I am content."));
print "\n<br><br>\n";
/**
 * creating a comment
 */
print "creating a comment:<br>";
print htmlentities(XML_Util::createComment("I am a comment."));
print "\n<br><br>\n";
/**
 * creating an XML tag with multiline mode
 */
$tag = array("qname" => "foo:bar", "namespaceUri" => "http://foo.com", "attributes" => array("key" => "value", "argh" => "fruit&vegetable"), "content" => "I'm inside the tag & contain dangerous chars");
print "creating a tag with qualified name and namespaceUri:<br>\n";
print "<pre>";
print htmlentities(XML_Util::createTagFromArray($tag, XML_UTIL_REPLACE_ENTITIES, true));
print "</pre>";
print "\n<br><br>\n";
/**
 * create an attribute string without replacing the entities
 */
$atts = array('series' => 'Starsky &amp; Hutch', 'channel' => 'ABC');
print "creating a attribute string, entities in values already had been replaced:<br>";
开发者ID:BackupTheBerlios,项目名称:dilps,代码行数:31,代码来源:example2.php

示例2: _serializeArray


//.........这里部分代码省略.........
                 // do indentation
                 if ($this->options[XML_SERIALIZER_OPTION_INDENT] !== null && $this->_tagDepth > 0) {
                     $string .= str_repeat($this->options[XML_SERIALIZER_OPTION_INDENT], $this->_tagDepth);
                 }
             }
             return rtrim($string);
         }
     }
     $scalarAsAttributes = false;
     if (is_array($this->options[XML_SERIALIZER_OPTION_SCALAR_AS_ATTRIBUTES]) && isset($this->options[XML_SERIALIZER_OPTION_SCALAR_AS_ATTRIBUTES][$tagName])) {
         $scalarAsAttributes = $this->options[XML_SERIALIZER_OPTION_SCALAR_AS_ATTRIBUTES][$tagName];
     } elseif ($this->options[XML_SERIALIZER_OPTION_SCALAR_AS_ATTRIBUTES] === true) {
         $scalarAsAttributes = true;
     }
     if ($scalarAsAttributes === true) {
         $this->expectError('*');
         foreach ($array as $key => $value) {
             if (is_scalar($value) && XML_Util::isValidName($key) === true) {
                 unset($array[$key]);
                 $attributes[$this->options[XML_SERIALIZER_OPTION_PREPEND_ATTRIBUTES] . $key] = $value;
             }
         }
         $this->popExpect();
     } elseif (is_array($scalarAsAttributes)) {
         $this->expectError('*');
         foreach ($scalarAsAttributes as $key) {
             if (!isset($array[$key])) {
                 continue;
             }
             $value = $array[$key];
             if (is_scalar($value) && XML_Util::isValidName($key) === true) {
                 unset($array[$key]);
                 $attributes[$this->options[XML_SERIALIZER_OPTION_PREPEND_ATTRIBUTES] . $key] = $value;
             }
         }
         $this->popExpect();
     }
     // check for empty array => create empty tag
     if (empty($array)) {
         $tag = array('qname' => $tagName, 'content' => $_content, 'attributes' => $attributes);
     } else {
         $this->_tagDepth++;
         $tmp = $_content . $this->options[XML_SERIALIZER_OPTION_LINEBREAKS];
         foreach ($array as $key => $value) {
             // do indentation
             if ($this->options[XML_SERIALIZER_OPTION_INDENT] !== null && $this->_tagDepth > 0) {
                 $tmp .= str_repeat($this->options[XML_SERIALIZER_OPTION_INDENT], $this->_tagDepth);
             }
             // copy key
             $origKey = $key;
             $this->expectError('*');
             // key cannot be used as tagname => use default tag
             $valid = XML_Util::isValidName($key);
             $this->popExpect();
             if (PEAR::isError($valid)) {
                 if ($this->options[XML_SERIALIZER_OPTION_CLASSNAME_AS_TAGNAME] && is_object($value)) {
                     $key = get_class($value);
                 } else {
                     $key = $this->_getDefaultTagname($tagName);
                 }
             }
             // once we've established the true $key, is there a tagmap for it?
             if (isset($this->options[XML_SERIALIZER_OPTION_TAGMAP][$key])) {
                 $key = $this->options[XML_SERIALIZER_OPTION_TAGMAP][$key];
             }
             $atts = array();
             if ($this->options[XML_SERIALIZER_OPTION_TYPEHINTS] === true) {
                 $atts[$this->options[XML_SERIALIZER_OPTION_ATTRIBUTE_TYPE]] = gettype($value);
                 if ($key !== $origKey) {
                     $atts[$this->options[XML_SERIALIZER_OPTION_ATTRIBUTE_KEY]] = (string) $origKey;
                 }
             }
             $tmp .= $this->_createXMLTag(array('qname' => $key, 'attributes' => $atts, 'content' => $value));
             $tmp .= $this->options[XML_SERIALIZER_OPTION_LINEBREAKS];
         }
         $this->_tagDepth--;
         if ($this->options[XML_SERIALIZER_OPTION_INDENT] !== null && $this->_tagDepth > 0) {
             $tmp .= str_repeat($this->options[XML_SERIALIZER_OPTION_INDENT], $this->_tagDepth);
         }
         if (trim($tmp) === '') {
             $tmp = null;
         }
         $tag = array('qname' => $tagName, 'content' => $tmp, 'attributes' => $attributes);
     }
     if ($this->options[XML_SERIALIZER_OPTION_TYPEHINTS] === true) {
         if (!isset($tag['attributes'][$this->options[XML_SERIALIZER_OPTION_ATTRIBUTE_TYPE]])) {
             $tag['attributes'][$this->options[XML_SERIALIZER_OPTION_ATTRIBUTE_TYPE]] = 'array';
         }
     }
     $string = '';
     if (!is_null($_comment)) {
         $string .= XML_Util::createComment($_comment);
         $string .= $this->options[XML_SERIALIZER_OPTION_LINEBREAKS];
         if ($this->options[XML_SERIALIZER_OPTION_INDENT] !== null && $this->_tagDepth > 0) {
             $string .= str_repeat($this->options[XML_SERIALIZER_OPTION_INDENT], $this->_tagDepth);
         }
     }
     $string .= $this->_createXMLTag($tag, false);
     return $string;
 }
开发者ID:retrogamer4ever,项目名称:php-tools,代码行数:101,代码来源:Serializer.php

示例3: htmlentities

 * creating an end element
 */
print 'creating an end element:<br>';
print htmlentities(XML_Util::createEndElement('myNs:myTag'));
print "\n<br><br>\n";
/**
 * creating a CData section
 */
print 'creating a CData section:<br>';
print htmlentities(XML_Util::createCDataSection('I am content.'));
print "\n<br><br>\n";
/**
 * creating a comment
 */
print 'creating a comment:<br>';
print htmlentities(XML_Util::createComment('I am a comment.'));
print "\n<br><br>\n";
/**
 * creating an XML tag with multiline mode
 */
$tag = array('qname' => 'foo:bar', 'namespaceUri' => 'http://foo.com', 'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable'), 'content' => 'I\'m inside the tag & contain dangerous chars');
print 'creating a tag with qualified name and namespaceUri:<br>';
print '<pre>';
print htmlentities(XML_Util::createTagFromArray($tag, XML_UTIL_REPLACE_ENTITIES, true));
print '</pre>';
print "\n<br><br>\n";
/**
 * create an attribute string without replacing the entities
 */
$atts = array('series' => 'Starsky &amp; Hutch', 'channel' => 'ABC');
print 'creating a attribute string, ' . 'entities in values already had been replaced:<br>';
开发者ID:crazy-max,项目名称:neard-bin-php,代码行数:31,代码来源:example2.php


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