• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

用PHP读取和编写XML DOM的实现代码_php技巧

php 搞代码 3年前 (2022-01-26) 17次浏览 已收录 0个评论

用 PHP 读取和编写可扩展标记语言(XML)看起来可能有点恐怖。实际上,XML 和它的所有相关技术可能是恐怖的,但是用 PHP 读取和编写 XML 不一定是项恐怖的任务。首先,需要学习一点关于 XML 的知识 —— 它是什么,用它做什么。然后,需要学习如何用 PHP 读取和编写 XML,而有许多种方式可以做这件事。
本文提供了 XML 的简短入门,然后解释如何用 PHP 读取和编写 XML。
什么是 XML?
XML 是一种数据存储格式。它没有定义保存什么数据,也没有定义数据的格式。XML 只是定义了标记和这些标记的属性。格式良好的 XML 标记看起来像这样:
Jack Herrington
这个 标记包含一些文本:Jack Herrington。
不包含文本的 XML 标记看起来像这样:

用 XML 对某件事进行编写的方式不止一种。例如,这个标记形成的输出与前一个标记相同:

也可以向 XML 标记添加属性。例如,这个 标记包含 first 和 last 属性:

也可以用 XML 对特殊字符进行编码。例如,& 符号可以像这样编码:
&
包含标记和属性的 XML 文件如果像示例一样格式化,就是格式良好的,这意味着标记是对称的,字符的编码正确。清单 1 是一份格式良好的 XML 的示例。

清单 1. XML 图书列表示例

 <BR> <BR> <BR>Jack Herrington <BR><title>PHP Hacks</title> <BR>O'Reilly <BR> <BR> <BR>Jack Herrington <BR><title>Podcasting Hacks</title> <BR>O'Reilly <BR> <BR> <BR>


清单 1 中的 XML 包含一个图书列表。父标记 包含一组 标记,每个 标记又包含 、 和 标记。 <BR>当 XML 文档的标记结构和内容得到外部模式文件的验证后,XML 文档就是正确的。模式文件可以用不同的格式指定。对于本文来说,所需要的只是格式良好的 XML。 <BR>如果觉得 XML 看起来很像超文本标记语言(HTML),那么就对了。XML 和 HTML 都是基于标记的语言,它们有许多相似之处。但是,要着重指出的是:虽然 XML 文档可能是格式良好的 HTML,但不是所有的 HTML 文档都是格式良好的 XML。换行标记(br)是 XML 和 HTML 之间区别的一个好例子。这个换行标记是格式良好的 HTML,但不是格式良好的 XML: <BR></p> <p>This is a paragraph<br /> <BR>With a line break</p> <p> <BR>这个换行标记是格式良好的 XML 和 HTML: <BR></p> <p>This is a paragraph<br /> <BR>With a line break</p><div><div class="_t33rkthes8f"></div><script type="text/javascript">(window.slotbydup = window.slotbydup || []).push({id: "u6795179",container: "_t33rkthes8f",async: true});</script></div> <p> <BR>如果要把 HTML 编写成同样是格式良好的 XML,请遵循 W3C<i style="color:transparent">本#文来源gaodai$ma#com搞$$代**码网$</i><button>搞代gaodaima码</button> 委员会的可扩展超文本标记语言(XHTML)标准。所有现代的浏览器都能呈现 XHTML。而且,还可以用 XML 工具读取 XHTML 并找出文档中的数据,这比解析 HTML 容易得多。 <BR><STRONG>使用 DOM 库读取 XML</STRONG> <BR>读取格式良好的 XML 文件最容易的方式是使用编译成某些 PHP 安装的文档对象模型 (DOM)库。DOM 库把整个 XML 文档读入内存,并用节点树表示它,如图 1 所示。 <BR>图 1. 图书 XML 的 XML DOM 树 <BR><BR>树顶部的 books 节点有两个 book 子标记。在每本书中,有 author、publisher 和 title 几个节点。author、publisher 和 title 节点分别有包含文本的文本子节点。 <BR>读取图书 XML 文件并用 DOM 显示内容的代码如清单 2 所示。 <BR>清单 2. 用 DOM 读取图书 XML <BR></p> <pre class="prettyprint"> <BR><?php <BR>$doc = new DOMDocument(); <BR>$doc->load( 'books.xml' ); <BR>$books = $doc->getElementsByTagName( "book" ); <BR>foreach( $books as $book ) <BR>{ <BR>$authors = $book->getElementsByTagName( "author" ); <BR>$author = $authors->item(0)->nodeValue; <BR>$publishers = $book->getElementsByTagName( "publisher" ); <BR>$publisher = $publishers->item(0)->nodeValue; <BR>$titles = $book->getElementsByTagName( "title" ); <BR>$title = $titles->item(0)->nodeValue; <BR>echo "$title - $author - $publisher\n"; <BR>} <BR>?> <BR></pre> <p> <BR>脚本首先创建一个 new DOMdocument 对象,用 load 方法把图书 XML 装入这个对象。之后,脚本用 getElementsByName 方法得到指定名称下的所有元素的列表。 <BR>在 book 节点的循环中,脚本用 getElementsByName 方法获得 author、publisher 和 title 标记的 nodeValue。nodeValue 是节点中的文本。脚本然后显示这些值。 <BR>可以在命令行上像这样运行 PHP 脚本: <BR>% php e1.php <BR>PHP Hacks – Jack Herrington – O’Reilly <BR>Podcasting Hacks – Jack Herrington – O’Reilly <BR>% <BR>可以看到,每个图书块输出一行。这是一个良好的开始。但是,如果不能访问 XML DOM 库该怎么办? <BR>用 SAX 解析器读取 XML <BR>读取 XML 的另一种方法是使用 XML Simple API(SAX)解析器。PHP 的大多数安装都包含 SAX 解析器。SAX 解析器运行在回调模型上。每次打开或关闭一个标记时,或者每次解析器看到文本时,就用节点或文本的信息回调用户定义的函数。 <BR>SAX 解析器的优点是,它是真正轻量级的。解析器不会在内存中长期保持内容,所以可以用于非常巨大的文件。缺点是编写 SAX 解析器回调是件非常麻烦的事。清单 3 显示了使用 SAX 读取图书 XML 文件并显示内容的代码。 <BR>清单 3. 用 SAX 解析器读取图书 XML <BR></p> <pre class="prettyprint"> <BR><?php <BR>$g_books = array(); <BR>$g_elem = null; <BR>function startElement( $parser, $name, $attrs ) <BR>{ <BR>global $g_books, $g_elem; <BR>if ( $name == 'BOOK' ) $g_books []= array(); <BR>$g_elem = $name; <BR>} <BR>function endElement( $parser, $name ) <BR>{ <BR>global $g_elem; <BR>$g_elem = null; <BR>} <BR>function textData( $parser, $text ) <BR>{ <BR>global $g_books, $g_elem; <BR>if ( $g_elem == 'AUTHOR' || <BR>$g_elem == 'PUBLISHER' || <BR>$g_elem == 'TITLE' ) <BR>{ <BR>$g_books[ count( $g_books ) - 1 ][ $g_elem ] = $text; <BR>} <BR>} <BR>$parser = xml_parser_create(); <BR>xml_set_element_handler( $parser, "startElement", "endElement" ); <BR>xml_set_character_data_handler( $parser, "textData" ); <BR>$f = fopen( 'books.xml', 'r' ); <BR>while( $data = fread( $f, 4096 ) ) <BR>{ <BR>xml_parse( $parser, $data ); <BR>} <BR>xml_parser_free( $parser ); <BR>foreach( $g_books as $book ) <BR>{ <BR>echo $book['TITLE']." - ".$book['AUTHOR']." - "; <BR>echo $book['PUBLISHER']."\n"; <BR>} <BR>?> <BR></pre> <p> <BR>脚本首先设置 g_books 数组,它在内存中容纳所有图书和图书信息,g_elem 变量保存脚本目前正在处理的标记的名称。然后脚本定义回调函数。在这个示例中,回调函数是 startElement、endElement 和 textData。在打开和关闭标记的时候,分别调用 startElement 和 endElement 函数。在开始和结束标记之间的文本上面,调用 textData。 <BR>在这个示例中,startElement 标记查找 book 标记,在 book 数组中开始一个新元素。然后,textData 函数查看当前元素,看它是不是 publisher、title 或 author 标记。如果是,函数就把当前文本放入当前图书。 <BR>为了让解析继续,脚本用 xml_parser_create 函数创建解析器。然后,设置回调句柄。之后,脚本读取文件并把文件的大块内容发送到解析器。在文件读取之后,xml_parser_free 函数删除解析器。脚本的末尾输出 g_books 数组的内容。 <BR>可以看到,这比编写 DOM 的同样功能要困难得多。如果没有 DOM 库也没有 SAX 库该怎么办?还有替代方案么? <BR>——————————————————————————– <BR>回页首 <BR>用正则表达式解析 XML <BR>可以肯定,即使提到这个方法,有些工程师也会批评我,但是确实可以用正则表达式解析 XML。清单 4 显示了使用 preg_ 函数读取图书文件的示例。 <BR>清单 4. 用正则表达式读取 XML <BR></p> <pre class="prettyprint"> <BR><?php <BR>$xml = ""; <BR>$f = fopen( 'books.xml', 'r' ); <BR>while( $data = fread( $f, 4096 ) ) { $xml .= $data; } <BR>fclose( $f ); <BR>preg_match_all( "/\<book\>(.*?)\<\/book\>/s", <BR>$xml, $bookblocks ); <BR>foreach( $bookblocks[1] as $block ) <BR>{ <BR>preg_match_all( "/\$block, $author ); <BR>preg_match_all( "/\<title\>(.*?)\<\/title\>/", <BR>$block, $title ); <BR>preg_match_all( "/\<publisher\>(.*?)\<\/publisher\>/", <BR>$block, $publisher ); <BR>echo( $title[1][0]." - ".$author[1][0]." - ". <BR>$publisher[1][0]."\n" ); <BR>} <BR>?> <BR></pre> <p>请注意这个代码有多短。开始时,它把文件读进一个大的字符串。然后用一个 regex 函数读取每个图书项目。最后用 foreach 循环,在每个图书块间循环,并提取出 author、title 和 publisher。 <BR>那么,缺陷在哪呢?使用正则表达式代码读取 XML 的问题是,它并没先进行检查,确保 XML 的格式良好。这意味着在读取之前,无法知道 XML 是否格式良好。而且,有些格式正确的 XML 可能与正则表达式不匹配,所以日后必须修改它们。 <BR>我从不建议使用正则表达式读取 XML,但是有时它是兼容性最好的方式,因为正则表达式函数总是可用的。不要用正则表达式读取直接来自用户的 XML,因为无法控制这类 XML 的格式或结构。应当一直用 DOM 库或 SAX 解析器读取来自用户的 XML。 <BR>——————————————————————————– <BR>回页首 <BR>用 DOM 编写 XML <BR>读取 XML 只是公式的一部分。该怎样编写 XML 呢?编写 XML 最好的方式就是用 DOM。清单 5 显示了 DOM 构建图书 XML 文件的方式。 <BR>清单 5. 用 DOM 编写图书 XML <BR></p> <pre class="prettyprint"> <BR><?php <BR>$books = array(); <BR>$books [] = array( <BR>'title' => 'PHP Hacks', <BR>'author' => 'Jack Herrington', <BR>'publisher' => "O'Reilly" <BR>); <BR>$books [] = array( <BR>'title' => 'Podcasting Hacks', <BR>'author' => 'Jack Herrington', <BR>'publisher' => "O'Reilly" <BR>); <BR>$doc = new DOMDocument(); <BR>$doc->formatOutput = true; <BR>$r = $doc->createElement( "books" ); <BR>$doc->appendChild( $r ); <BR>foreach( $books as $book ) <BR>{ <BR>$b = $doc->createElement( "book" ); <BR>$author = $doc->createElement( "author" ); <BR>$author->appendChild( <BR>$doc->createTextNode( $book['author'] ) <BR>); <BR>$b->appendChild( $author ); <BR>$title = $doc->createElement( "title" ); <BR>$title->appendChild( <BR>$doc->createTextNode( $book['title'] ) <BR>); <BR>$b->appendChild( $title ); <BR>$publisher = $doc->createElement( "publisher" ); <BR>$publisher->appendChild( <BR>$doc->createTextNode( $book['publisher'] ) <BR>); <BR>$b->appendChild( $publisher ); <BR>$r->appendChild( $b ); <BR>} <BR>echo $doc->saveXML(); <BR>?> <BR></pre> <p>在脚本的顶部,用一些示例图书装入了 books 数组。这个数据可以来自用户也可以来自数据库。 <BR>示例图书装入之后,脚本创建一个 new DOMDocument,并把根节点 books 添加到它。然后脚本为每本书的 author、title 和 publisher 创建节点,并为每个节点添加文本节点。每个 book 节点的最后一步是重新把它添加到根节点 books。 <BR>脚本的末尾用 saveXML 方法把 XML 输出到控制台。(也可以用 save 方法创建一个 XML 文件。)脚本的输出如清单 6 所示。 <BR>清单 6. DOM 构建脚本的输出 <BR></p> <pre class="prettyprint"> <BR>php e4.php <BR><?xml version="1.0"?> <BR> <BR> <BR>Jack Herrington <BR><title>PHP Hacks</title> <BR>O'Reilly <BR> <BR> <BR>Jack Herrington <BR><title>Podcasting Hacks</title> <BR>O'Reilly <BR> <BR> <BR></pre> <p> <BR>使用 DOM 的真正价值在于它创建的 XML 总是格式正确的。但是如果不能用 DOM 创建 XML 时该怎么办? <BR>——————————————————————————– <BR>回页首 <BR>用 PHP 编写 XML <BR>如果 DOM 不可用,可以用 PHP 的文本模板编写 XML。清单 7 显示了 PHP 如何构建图书 XML 文件。 <BR>清单 7. 用 PHP 编写图书 XML <BR></p> <pre class="prettyprint"> <BR><?php <BR>$books = array(); <BR>$books [] = array( <BR>'title' => 'PHP Hacks', <BR>'author' => 'Jack Herrington', <BR>'publisher' => "O'Reilly" <BR>); <BR>$books [] = array( <BR>'title' => 'Podcasting Hacks', <BR>'author' => 'Jack Herrington', <BR>'publisher' => "O'Reilly" <BR>); <BR>?> <BR> <BR><?php <BR>foreach( $books as $book ) <BR>{ <BR>?> <BR> <BR><title><?php echo( $book['title'] ); ?></title> <BR><?php echo( $book['author'] ); ?> <BR> <BR><?php echo( $book['publisher'] ); ?> <BR> <BR> <BR><?php <BR>} <BR>?> <BR> <BR></pre> <p>脚本的顶部与 DOM 脚本类似。脚本的底部打开 books 标记,然后在每个图书中迭代,创建 book 标记和所有的内部 title、author 和 publisher 标记。 <BR>这种方法的问题是对实体进行编码。为了确保实体编码正确,必须在每个项目上调用 htmlentities 函数,如清单 8 所示。 <BR>清单 8. 使用 htmlentities 函数对实体编码 <BR></p> <pre class="prettyprint"> <BR> <BR><?php <BR>foreach( $books as $book ) <BR>{ <BR>$title = htmlentities( $book['title'], ENT_QUOTES ); <BR>$author = htmlentities( $book['author'], ENT_QUOTES ); <BR>$publisher = htmlentities( $book['publisher'], ENT_QUOTES ); <BR>?> <BR> <BR><title><?php echo( $title ); ?></title> <BR><?php echo( $author ); ?> <BR><?php echo( $publisher ); ?> <BR> <BR> <BR><?php <BR>} <BR>?> <BR> <BR></pre> <p>这就是用基本的 PHP 编写 XML 的烦人之处。您以为自己创建了完美的 XML,但是在试图使用数据的时候,马上就会发现某些元素的编码不正确。 <BR>——————————————————————————– <BR>结束语 <BR>XML 周围总有许多夸大之处和混淆之处。但是,并不像您想像的那么难 —— 特别是在 PHP 这样优秀的语言中。在理解并正确地实现了 XML 之后,就会发现有许多强大的工具可以使用。XPath 和 XSLT 就是这样两个值得研究的工具。</p> <hr /><div class="open-message">搞代码网(<a href="www.gaodaima.com" target="_blank" title="gaodaima.com">gaodaima.com</a>)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱<a>chengxuyuan@gaodaima.com‍</a>,我们会在看到邮件的第一时间内为您处理,或直接联系<a>QQ:872152909</a>。本网站采用<a href="https://www.gaodaima.com/go.html?url=http://creativecommons.org/licenses/by-nc-sa/3.0/" rel="nofollow" target="_blank" title="BY-NC-SA授权协议">BY-NC-SA</a>协议进行授权 <br >转载请注明原文链接:<a href="https://www.gaodaima.com/391663.html" target="_blank" title="用PHP读取和编写XML DOM的实现代码_php技巧">用PHP读取和编写XML DOM的实现代码_php技巧</a><a id="spreadAds" target="_blank" href="" onclick="spreadAds()"></a><a id="spreadAds2" target="_blank" href=""></a> </div> </p> <div class="article-social"> <a href="javascript:;" data-action="ding" data-id="391663" id="Addlike" class="action"><i class="fa fa-heart-o"></i>喜欢 (<span class="count">0</span>)</a><span class="or"><style>.article-social .weixin:hover{background:#fff;}</style><a class="weixin" style="border-bottom:0px;font-size:15pt;cursor:pointer;">赏<div class="weixin-popover"><div class="popover bottom in"><div class="arrow"></div><div class="popover-title"><center>[搞代码]</center></div><div class="popover-content"><img width="200px" height="200px" src="http://www.gaodaima.com/wp-content/uploads/hai_AliPay.png" ></div></div></div></a></span><span class="action action-share bdsharebuttonbox"><i class="fa fa-share-alt"></i>分享 (<span class="bds_count" data-cmd="count" title="累计分享0次">0</span>)<div class="action-popover"><div class="popover top in"><div class="arrow"></div><div class="popover-content"><a href="#" class="sinaweibo fa fa-weibo" data-cmd="tsina" title="分享到新浪微博"></a><a href="#" class="bds_qzone fa fa-star" data-cmd="qzone" title="分享到QQ空间"></a><a href="#" class="qq fa fa-qq" data-cmd="sqq" title="分享到QQ好友"></a><a href="#" class="bds_renren fa fa-renren" data-cmd="renren" title="分享到人人网"></a><a href="#" class="bds_weixin fa fa-weixin" data-cmd="weixin" title="分享到微信"></a><a href="#" class="bds_more fa fa-ellipsis-h" data-cmd="more"></a></div></div></div></span></div> </article> <footer class="article-footer"> </footer> <nav class="article-nav"><div class="_d13vl98i0pw"></div><script type="text/javascript"> (window.slotbydup = window.slotbydup || []).push({ id: "u6795176", container: "_d13vl98i0pw", async: true });</script> </nav><div id="donatecoffee" style="overflow:auto;display:none;"><img width="400" height="400" alt="支持作者一杯咖啡" src="http://www.gaodaima.com/wp-content/uploads/hai_AliPay.png"></div> <div class="related_top"> <div class="related_posts"><ul class="related_img"> <li class="related_box" > <a href="https://www.gaodaima.com/432021.html" title="利用微信公众号提供的官方API上传图片获取永久图片素材当图床用" target="_blank"><img class="thumb" style="width:185px;height:110px" data-original="https://www.gaodaima.com/wp-content/themes/Git-alpha/timthumb.php?src=https://www.gaodaima.com/wp-content/themes/Git-alpha/assets/img/pic/9.jpg&h=110&w=185&q=90&zc=1&ct=1" alt="利用微信公众号提供的官方API上传图片获取永久图片素材当图床用" /><br><span class="r_title">利用微信公众号提供的官方API上传图片获取永久图片素材当图床用</span></a> </li> <li class="related_box" > <a href="https://www.gaodaima.com/432022.html" title="不用编码的高端网站建设神器" target="_blank"><img class="thumb" style="width:185px;height:110px" data-original="https://www.gaodaima.com/wp-content/themes/Git-alpha/timthumb.php?src=https://www.gaodaima.com/wp-content/themes/Git-alpha/assets/img/pic/7.jpg&h=110&w=185&q=90&zc=1&ct=1" alt="不用编码的高端网站建设神器" /><br><span class="r_title">不用编码的高端网站建设神器</span></a> </li> <li class="related_box" > <a href="https://www.gaodaima.com/432019.html" title="精品SSM框架个人健康服务预约系统设计和实现源码查重报告代码讲解论文中期检查ppt已降重" target="_blank"><img class="thumb" style="width:185px;height:110px" data-original="https://www.gaodaima.com/wp-content/themes/Git-alpha/timthumb.php?src=https://www.gaodaima.com/wp-content/themes/Git-alpha/assets/img/pic/8.jpg&h=110&w=185&q=90&zc=1&ct=1" alt="精品SSM框架个人健康服务预约系统设计和实现源码查重报告代码讲解论文中期检查ppt已降重" /><br><span class="r_title">精品SSM框架个人健康服务预约系统设计和实现源码查重报告代码讲解论文中期检查ppt已降重</span></a> </li> <li class="related_box" > <a href="https://www.gaodaima.com/432020.html" title="php设计模式一单例工厂" target="_blank"><img class="thumb" style="width:185px;height:110px" data-original="https://www.gaodaima.com/wp-content/themes/Git-alpha/timthumb.php?src=https://www.gaodaima.com/wp-content/themes/Git-alpha/assets/img/pic/1.jpg&h=110&w=185&q=90&zc=1&ct=1" alt="php设计模式一单例工厂" /><br><span class="r_title">php设计模式一单例工厂</span></a> </li> </ul><div class="relates"><div class="_mw9fz31sqco"></div><script type="text/javascript"> (window.slotbydup = window.slotbydup || []).push({ id: "u6795180", container: "_mw9fz31sqco", async: true });</script><ul><li><i class="fa fa-minus"></i><a target="_blank" href="https://www.gaodaima.com/432021.html">利用微信公众号提供的官方API上传图片获取永久图片素材当图床用</a></li><li><i class="fa fa-minus"></i><a target="_blank" href="https://www.gaodaima.com/432022.html">不用编码的高端网站建设神器</a></li><li><i class="fa fa-minus"></i><a target="_blank" href="https://www.gaodaima.com/432019.html">精品SSM框架个人健康服务预约系统设计和实现源码查重报告代码讲解论文中期检查ppt已降重</a></li><li><i class="fa fa-minus"></i><a target="_blank" href="https://www.gaodaima.com/432020.html">php设计模式一单例工厂</a></li><li><i class="fa fa-minus"></i><a target="_blank" href="https://www.gaodaima.com/432017.html">Go-内联优化能让程序快多少</a></li><li><i class="fa fa-minus"></i><a target="_blank" href="https://www.gaodaima.com/432018.html">推荐一个PHP-Tree无限级分类组件-BlueMTree</a></li><li><i class="fa fa-minus"></i><a target="_blank" href="https://www.gaodaima.com/432015.html">php设计模式二注册树</a></li><li><i class="fa fa-minus"></i><a target="_blank" href="https://www.gaodaima.com/432016.html">Gmail如何跟踪邮件阅读状态</a></li></ul></div></div> </div> <div id="comment-ad" class="banner banner-related"><div class="_9madbukio7r"></div><script type="text/javascript"> (window.slotbydup = window.slotbydup || []).push({ id: "u6677406", container: "_9madbukio7r", async: true });</script><!-- 多条广告如下脚本只需引入一次 --><script type="text/javascript" src="//cpro.baidustatic.com/cpro/ui/cm.js" async="async" defer="defer" ></script></div> <div id="respond" class="no_webshot"> <form action="https://www.gaodaima.com/asdloie8574asdqwexzxdqwertasdqwe.php" method="post" id="commentform"> <div class="comt-title"> <div class="comt-avatar pull-left"> <img src="https://cdn.v2ex.com/gravatar/?s=50" class="avatar avatar-108"> </div> <div class="comt-author pull-left"> 发表我的评论 </div> <a id="cancel-comment-reply-link" class="pull-right" href="javascript:;">取消评论</a> </div> <div class="comt"> <div class="comt-box"> <textarea placeholder="说点什么吧…" class="input-block-level comt-area" name="comment" id="comment" cols="100%" rows="3" tabindex="1" onkeydown="if(event.ctrlKey&&event.keyCode==13){document.getElementById('submit').click();return false};"></textarea> <div class="comt-ctrl"> <button class="btn btn-primary pull-right" type="submit" name="submit" id="submit" tabindex="5"><i class="fa fa-check-square-o"></i> 提交评论</button> <div class="comt-tips pull-right"><input type='hidden' name='comment_post_ID' value='391663' id='comment_post_ID' /><input type='hidden' name='comment_parent' id='comment_parent' value='0' /><p style="display: none;"><input type="hidden" id="akismet_comment_nonce" name="akismet_comment_nonce" value="5994f112d6" /></p><label for="comment_mail_notify" class="checkbox inline" style="padding-top:0;"><input name="comment_mail_notify" id="comment_mail_notify" value="comment_mail_notify" checked="checked" type="checkbox">评论通知</label><p style="display: none;"><input type="hidden" id="ak_js" name="ak_js" value="50"/></p></div> <span data-type="comment-insert-smilie" class="muted comt-smilie"><i class="fa fa-smile-o"></i> 表情</span> <span class="muted ml5 comt-img"><i class="fa fa-picture-o"></i><a href="javascript:SIMPALED.Editor.img()" style="color:#999999"> 贴图</a></span> <span class="muted ml5 comt-strong"><i class="fa fa-bold"></i><a href="javascript:SIMPALED.Editor.strong()" style="color:#999999"> 加粗</a></span> <span class="muted ml5 comt-del"><i class="fa fa-strikethrough"></i><a href="javascript:SIMPALED.Editor.del()" style="color:#999999"> 删除线</a></span> <span class="muted ml5 comt-center"><i class="fa fa-align-center"></i><a href="javascript:SIMPALED.Editor.center()" style="color:#999999"> 居中</a></span> <span class="muted ml5 comt-italic"><i class="fa fa-italic"></i><a href="javascript:SIMPALED.Editor.italic()" style="color:#999999"> 斜体</a></span> <span class="muted ml5 comt-sign"><i class="fa fa-pencil-square-o"></i><a href="javascript:SIMPALED.Editor.daka()" style="color:#999999"> 签到</a></span> </div> </div> <div class="comt-comterinfo" id="comment-author-info" > <h4>Hi,您需要填写昵称和邮箱!</h4> <ul> <li class="form-inline"><label class="hide" for="author">昵称</label><input class="ipt" type="text" name="author" id="author" value="" tabindex="2" placeholder="昵称"><span class="help-inline">昵称 (必填)</span></li> <li class="form-inline"><label class="hide" for="email">邮箱</label><input class="ipt" type="text" name="email" id="email" value="" tabindex="3" placeholder="邮箱"><span class="help-inline">邮箱 (必填)</span></li> <li class="form-inline"><label class="hide" for="url">网址</label><input class="ipt" type="text" name="url" id="url" value="" tabindex="4" placeholder="网址"><span class="help-inline">网址</span></li> </ul> </div> </div> </form> </div> <div class="banner banner-comment"><div class="_z8s30eeiks"></div><script type="text/javascript"> (window.slotbydup = window.slotbydup || []).push({ id: "u6677645", container: "_z8s30eeiks", async: true });</script></div> </div></div><aside class="sidebar"><div class="widget git_banner"><div class="git_banner_inner"><div class="_ij8d6cgwm0r"></div><script type="text/javascript"> (window.slotbydup = window.slotbydup || []).push({ id: "u6795162", container: "_ij8d6cgwm0r", async: true });</script></div></div><div class="widget git_banner"><div class="git_banner_inner"><script type="text/javascript"> /*360*300-pc-侧边栏多彩标签云*/ var cpro_id = "u6795164";</script><script type="text/javascript" src="http://cpro.baidustatic.com/cpro/ui/c.js"></script></div></div><div class="widget git_postlist"><div class="title"><h2>热门文章</h2></div><ul> <li> <a target="_blank" href="https://www.gaodaima.com/320141.html" title="PHP发展的现状和前景" ><span class="thumbnail"><img width="100px" height="64px" src="https://www.gaodaima.com/wp-content/themes/Git-alpha/timthumb.php?src=https://www.gaodaima.com/wp-content/themes/Git-alpha/assets/img/pic/10.jpg&h=64&w=100&q=90&zc=1&ct=1" alt="PHP发展的现状和前景" /></span><span class="text">PHP发展的现状和前景</span><span class="muted">2022-01-24</span><span class="muted">0</span></a> </li> <li> <a target="_blank" href="https://www.gaodaima.com/295546.html" title="php+mysql协同过滤算法的实现" ><span class="thumbnail"><img width="100px" height="64px" src="https://www.gaodaima.com/wp-content/themes/Git-alpha/timthumb.php?src=https://www.gaodaima.com/wp-content/themes/Git-alpha/assets/img/pic/10.jpg&h=64&w=100&q=90&zc=1&ct=1" alt="php+mysql协同过滤算法的实现" /></span><span class="text">php+mysql协同过滤算法的实现</span><span class="muted">2022-01-23</span><span class="muted">0</span></a> </li> <li> <a target="_blank" href="https://www.gaodaima.com/138433.html" title="java设计模式之实现对象池模式示例分享" ><span class="thumbnail"><img width="100px" height="64px" src="https://www.gaodaima.com/wp-content/themes/Git-alpha/timthumb.php?src=https://www.gaodaima.com/wp-content/themes/Git-alpha/assets/img/pic/11.jpg&h=64&w=100&q=90&zc=1&ct=1" alt="java设计模式之实现对象池模式示例分享" /></span><span class="text">java设计模式之实现对象池模式示例分享</span><span class="muted">2022-01-06</span><span class="muted">0</span></a> </li> <li> <a target="_blank" href="https://www.gaodaima.com/111922.html" title="浅谈Spring Cloud Ribbon的原理" ><span class="thumbnail"><img width="100px" height="64px" src="https://www.gaodaima.com/wp-content/themes/Git-alpha/timthumb.php?src=https://www.gaodaima.com/wp-content/themes/Git-alpha/assets/img/pic/9.jpg&h=64&w=100&q=90&zc=1&ct=1" alt="浅谈Spring Cloud Ribbon的原理" /></span><span class="text">浅谈Spring Cloud Ribbon的原理</span><span class="muted">2022-01-06</span><span class="muted">0</span></a> </li> <li> <a target="_blank" href="https://www.gaodaima.com/357272.html" title="php里怎么防止用户重复登录" ><span class="thumbnail"><img width="100px" height="64px" src="https://www.gaodaima.com/wp-content/themes/Git-alpha/timthumb.php?src=https://www.gaodaima.com/wp-content/themes/Git-alpha/assets/img/pic/4.jpg&h=64&w=100&q=90&zc=1&ct=1" alt="php里怎么防止用户重复登录" /></span><span class="text">php里怎么防止用户重复登录</span><span class="muted">2022-01-25</span><span class="muted">0</span></a> </li> <li> <a target="_blank" href="https://www.gaodaima.com/100326.html" title="php怎么不去重的合并数组" ><span class="thumbnail"><img width="100px" height="64px" src="https://www.gaodaima.com/wp-content/themes/Git-alpha/timthumb.php?src=https://www.gaodaima.com/wp-content/themes/Git-alpha/assets/img/pic/11.jpg&h=64&w=100&q=90&zc=1&ct=1" alt="php怎么不去重的合并数组" /></span><span class="text">php怎么不去重的合并数组</span><span class="muted">2022-01-04</span><span class="muted">0</span></a> </li> </ul></div><div class="widget git_banner"><div class="git_banner_inner"><div class="_6zq48yj6kr"></div><script type="text/javascript"> (window.slotbydup = window.slotbydup || []).push({ id: "u6700845", container: "_6zq48yj6kr", async: true });</script></div></div><div class="widget git_banner"><div class="git_banner_inner"><div class="_zx9adhkf46s"></div><script type="text/javascript"> (window.slotbydup = window.slotbydup || []).push({ id: "u6795161", container: "_zx9adhkf46s", async: true });</script></div></div><div class="widget git_banner"><div class="git_banner_inner"><div class="_4st5c4knrf5"></div><script type="text/javascript"> (window.slotbydup = window.slotbydup || []).push({ id: "u6795163", container: "_4st5c4knrf5", async: true });</script></div></div></aside> <script type="text/javascript" src="https://www.gaodaima.com/wp-content/plugins/g-prettify/prettify.js"></script></section><div id="footbar" style="border-top: 2px solid #8E44AD;"><ul><li><p class="first">版权声明</p><span>本站的文章和资源来自互联网或者站长<br>的原创,按照 CC BY -NC -SA 3.0 CN<br>协议发布和共享,转载或引用本站文章<br>应遵循相同协议。如果有侵犯版权的资<br>源请尽快联系站长,我们会在24h内删<br>除有争议的资源。</span></li><li><p class="second">网站驱动</p><span><ul><li><a href="http://www.gaodaima.com/go/aliyun" title="部署在阿里云" target="_blank">部署在阿里云</a></li><li><a href="http://www.gaodaima.com/go/qiniu" title="由七牛云储存提供 CDN 加速" target="_blank">由七牛云储存提供 CDN 加速</a></li></ul></span></li><li><p class="third">友情链接</p><span><ul><li><a href="http://www.gaodaima.com" title="搞代码" target="_blank">搞代码</a></li><li><a href="http://www.gaodaima.com/go/bt" title="宝塔bt" target="_blank">宝塔镇河妖</a></li></ul></span></li><li><p class="fourth">强烈推荐</p><span><ul><li><a href="http://www.gaodaima.com/go/tencentCloud" title="腾讯云" target="_blank">腾讯云</a></li><!--<li><a href="http://www.gaodaima.com/go/lanzou" title="蓝奏云" target="_blank">蓝奏云</a></li>--><li><a href="http://www.gaodaima.com/go/2345" title="2345" target="_blank">二三四五</a></li></ul></span></li></ul></div><footer style="border-top: 1px solid ;background-image: url('data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAUAAA/+4ADkFkb2JlAGTAAAAAAf/bAIQAAgICAgICAgICAgMCAgIDBAMCAgMEBQQEBAQEBQYFBQUFBQUGBgcHCAcHBgkJCgoJCQwMDAwMDAwMDAwMDAwMDAEDAwMFBAUJBgYJDQsJCw0PDg4ODg8PDAwMDAwPDwwMDAwMDA8MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM/8AAEQgAAgAKAwERAAIRAQMRAf/EAEwAAQEAAAAAAAAAAAAAAAAAAAAJAQEAAAAAAAAAAAAAAAAAAAAAEAEBAAAAAAAAAAAAAAAAAAAAlREBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEQMRAD8Ah7DAhg//2Q=='); background-repeat: repeat;" class="footer"><div class="footer-inner"><div class="footer-copyright">Copyright © 2017-2025 <a href="/" title="搞代码">搞代码</a> | <a href="http://www.gaodaima.com/mzsm" title="免责声明" rel="nofollow" target="_blank">免责声明</a> | <a href="http://www.beian.gov.cn" target="_blank" rel="nofollow"> 桂ICP备16000922号-2</a> | <a href="/sitemap.html" target="_blank" title="站点地图(HTML版)">网站地图</a> <span class="trackcode pull-right"><script>var _hmt = _hmt || [];(function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?8b0b664e103f4882d4fab2b8d3bc6639"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s);})();</script></span></div></div></footer><script type="text/javascript">document.body.oncopy=function(){alert("复制成功!若要转载请务必保留原文链接,申明来源,谢谢合作!");}</script><script type="text/javascript">eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1;};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p;}('9 m(4,a){7 k=p;7 5=b n();5.w(5.x()+k*j*j*t);3.c=4+"="+q(a)+";u="+5.s()+";v=/"}9 h(4){7 8,g=b y("(^| )"+4+"=([^;]*)(;|$)");f(8=3.c.o(g))d r(8[2]);i d\'\'}f(h(\'1\')!=\'e\'){3.6(\'1\').M=\'N: K;z-O: R;Q: 0;P: 0;J: 0;L: 0;D:A;\';3.6(\'1\').B=\'E://H.I.F/G/C\'}i{3.6("1").l()}9 1(){3.6("1").l();m(\'1\',\'e\')}',54,54,'|spreadAds||document|name|exp|getElementById|var|arr|function|value|new|cookie|return|true|if|reg|GetCookie|else|60|Days|remove|SetCookie|Date|match|12|escape|unescape|toGMTString|1000|expires|path|setTime|getTime|RegExp||default|href|jdjz|cursor|http|com|go|www|gaodaima|left|fixed|right|style|position|index|bottom|top|9999'.split('|'),0,{}))</script><script type='text/javascript' src='https://www.gaodaima.com/wp-content/themes/Git-alpha/assets/js/app.js'></script><script async="async" type='text/javascript' src='https://www.gaodaima.com/wp-content/plugins/akismet/_inc/form.js'></script><!-- 88 次查询 用时 4.290 秒, 耗费了 30.82MB 内存 --><script>with(document)0[(getElementsByTagName("head")[0]||body).appendChild(createElement("script")).src="https://cdn.jsdelivr.net/gh/yunluo/GitCafeApi/static/api/js/share.js?v=89860593.js?cdnversion="+~(-new Date()/36e5)];</script></body></html><!--Performance optimized by Redis Object Cache. Learn more: https://wprediscache.comRetrieved 1839 objects (353 KB) from Redis using PhpRedis (v4.3.0).--> <!--压缩前的大小: 58820 bytes; 压缩后的大小: 57905 bytes; 节约:1.56% -->