當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。