찾다
백엔드 개발PHP 튜토리얼使用PHP 5.0 轻松解析XML文档_PHP

使用PHP 5.0 轻松解析XML文档_PHP

Jun 01, 2016 pm 12:33 PM
idname사용문서분석하다쉬운

用sax方式的时候,要自己构建3个函数,而且要直接用这三的函数来返回数据, 要求较强的逻辑。 在处理不同结构的xml的时候, 还要重新进行构造这三个函数,麻烦!

  用dom方式,倒是好些,但是他把每个节点都看作是一个node,操作起来要写好多的代码, 麻烦!

  网上有好多的开源的xml解析的类库, 以前看过几个,但是心里总是觉得不踏实,感觉总是跟在别人的屁股后面.

  这几天在搞java, 挺累的,所以决定换换脑袋,写点php代码,为了防止以后xml解析过程再令我犯难,就花了一天的时间写了下面一个xml解析的类,于是就有了下面的东西。

  实现方式是通过包装"sax方式的解析结果"来实现的. 总的来说,对于我个人来说挺实用的,性能也还可以,基本上可以完成大多数的处理要求。

  功能:

  1、 对基本的xml文件的节点进行 查询 / 添加 / 修改 / 删除 工作.

  2、导出xml文件的所有数据到一个数组里面.

  3、整个设计采用了oo方式,在操作结果集的时候, 使用方法类似于dom

  缺点:

  1、 每个节点最好都带有一个id(看后面的例子), 每个“节点名字”=“节点的标签_节点的id”,如果这个id值没有设置,程序将自动给他产生一个id,这个id就是这个节点在他的上级节点中的位置编号,从0开始。

   2、 查询某个节点的时候可以通过用“|”符号连接“节点名字”来进行。这些“节点名字”都是按顺序写好的上级节点的名字。

  使用说明:

  运行下面的例子,在执行结果页面上可以看到函数的使用说明

  代码是通过php5来实现的,在php4中无法正常运行。

  由于刚刚写完,所以没有整理文档,下面的例子演示的只是一部分的功能,代码不是很难,要是想知道更多的功能,可以研究研究源代码。

  目录结构:

      test.php
      test.xml
      xml / SimpleDocumentBase.php
      xml / SimpleDocumentNode.php
      xml / SimpleDocumentRoot.php
      xml / SimpleDocumentParser.php

  文件:test.xml


<?xml version="1.0" encoding="GB2312"?><shop> <name>华联</name> <address>北京长安街-9999号</address> <desc>连锁超市</desc> <cat id="food">  <goods id="food11">   <name>food11</name>   <price>12.90</price>  </goods>  <goods id="food12">   <name>food12</name>   <price>22.10</price>   <desc creator="hahawen">好东西推荐</desc>  </goods> </cat> <cat>  <goods id="tel21">   <name>tel21</name>   <price>1290</price>  </goods> </cat> <cat id="coat">  <goods id="coat31">   <name>coat31</name>   <price>112</price>  </goods>  <goods id="coat32">   <name>coat32</name>   <price>45</price>  </goods> </cat> <special id="hot">  <goods>   <name>hot41</name>   <price>99</price>  </goods> </special></shop>

 

   文件:test.php


  <?php
    require_once "xml/SimpleDocumentParser.php";    require_once "xml/SimpleDocumentBase.php";    require_once "xml/SimpleDocumentRoot.php";    require_once "xml/SimpleDocumentNode.php";   $test = new SimpleDocumentParser();    $test->parse("test.xml");    $dom = $test->getSimpleDocument();    echo "<pre>";    echo "<hr><font color=red>";    echo "下面是通过函数getSaveData()返回的整个xml数据的数组";    echo "</font><hr>";    print_r($dom->getSaveData());    echo "<hr><font color=red>";    echo "下面是通过setValue()函数,给给根节点添加信息,添加后显示出结果xml文件的内容";    echo "</font><hr>";    $dom->setValue("telphone", "123456789");    echo htmlspecialchars($dom->getSaveXml());    echo "<hr><font color=red>";    echo "下面是通过getNode()函数,返回某一个分类下的所有商品的信息";    echo "</font><hr>";    $obj = $dom->getNode("cat_food");    $nodeList = $obj->getNode();    foreach($nodeList as $node){    $data = $node->getValue();    echo "<font color=red>商品名:".$data[name]."</font><br>";    print_R($data);    print_R($node->getAttribute());    }    echo "<hr><font color=red>";    echo "下面是通过findNodeByPath()函数,返回某一商品的信息";    echo "</font><hr>";    $obj = $dom->findNodeByPath("cat_food|goods_food11");    if(!is_object($obj)){    echo "该商品不存在";    }else{    $data = $obj->getValue();    echo "<font color=red>商品名:".$data[name]."</font><br>";    print_R($data);    print_R($obj->getAttribute());    }   echo "<hr><font color=red>";    echo "下面是通过setValue()函数,给商品\"food11\"添加属性, 然后显示添加后的结果";    echo "</font><hr>";    $obj = $dom->findNodeByPath("cat_food|goods_food11");    $obj->setValue("leaveword", array("value"=>"这个商品不错",          "attrs"=>array("author"=>"hahawen", "date"=>date('Y-m-d'))));    echo htmlspecialchars($dom->getSaveXml());    echo "<hr><font color=red>";    echo "下面是通过removeValue()/removeAttribute()函数,          给商品\"food11\"改变和删除属性, 然后显示操作后的结果";    echo "</font><hr>";    $obj = $dom->findNodeByPath("cat_food|goods_food12");    $obj->setValue("name", "new food12");    $obj->removeValue("desc");    echo htmlspecialchars($dom->getSaveXml());    echo "<hr><font color=red>";    echo "下面是通过createNode()函数,添加商品, 然后显示添加后的结果";    echo "</font><hr>";    $obj = $dom->findNodeByPath("cat_food");    $newObj = $obj->createNode("goods", array("id"=>"food13"));    $newObj->setValue("name", "food13");    $newObj->setValue("price", 100);    echo htmlspecialchars($dom->getSaveXml());    echo "<hr><font color=red>";    echo "下面是通过removeNode()函数,删除商品, 然后显示删除后的结果";    echo "</font><hr>";    $obj = $dom->findNodeByPath("cat_food");    $obj->removeNode("goods_food12");    echo htmlspecialchars($dom->getSaveXml());  ?>
 

 

文件:SimpleDocumentParser.php


<?php
/**
 *=========================================================
 *
 * @author     hahawen(大龄青年) 
 * @since      2004-12-04
 * @copyright  Copyright (c) 2004, NxCoder Group
 *
 *=========================================================
 */
/**
 * class SimpleDocumentParser
 * use SAX parse xml file, and build SimpleDocumentObject
 * all this pachage's is work for xml file, and method is action as DOM.
 *
 * @package SmartWeb.common.xml
 * @version 1.0
 */
class SimpleDocumentParser
{
 private $domRootObject = null;
 private $currentNO = null;
 private $currentName = null;
 private $currentValue = null;
 private $currentAttribute = null;
 public function getSimpleDocument()
 {
     return $this->domRootObject;
 }
 public function parse($file)
 {
        $xmlParser = xml_parser_create();
     xml_parser_set_option($xmlParser,XML_OPTION_CASE_FOLDING, 0);
     xml_parser_set_option($xmlParser,XML_OPTION_SKIP_WHITE, 1);
     xml_parser_set_option($xmlParser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
     xml_set_object($xmlParser, $this);
     xml_set_element_handler($xmlParser, "startElement", "endElement");
     xml_set_character_data_handler($xmlParser, "characterData");
        if (!xml_parse($xmlParser, file_get_contents($file)))
            die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xmlParser)),        xml_get_current_line_number($xmlParser)));
     xml_parser_free($xmlParser);
 }
 private function startElement($parser, $name, $attrs)
 {
        $this->currentName = $name;
        $this->currentAttribute = $attrs;
        if($this->currentNO == null)
        {
         $this->domRootObject = new SimpleDocumentRoot($name);
         $this->currentNO = $this->domRootObject;
        }
        else
        {
         $this->currentNO = $this->currentNO->createNode($name, $attrs);
        }
 }
    private function endElement($parser, $name)
    {
        if($this->currentName==$name)
        {
         $tag = $this->currentNO->getSeq();
         $this->currentNO = $this->currentNO->getPNodeObject();
            if($this->currentAttribute!=null && sizeof($this->currentAttribute)>0)
          $this->currentNO->setValue($name, array('value'=>$this->currentValue,        'attrs'=>$this->currentAttribute));
         else
                $this->currentNO->setValue($name, $this->currentValue);
            $this->currentNO->removeNode($tag);
        }
        else
        {
      $this->currentNO = (is_a($this->currentNO, 'SimpleDocumentRoot'))? null:         $this->currentNO->getPNodeObject();
        }
 }
 private function characterData($parser, $data)
 {
        $this->currentValue = iconv('UTF-8', 'GB2312', $data);
 }
 function __destruct()
 {
     unset($this->domRootObject);
 }
}
?>
     
 


  文件:SimpleDocumentBase.php

<?php
/**
 *=========================================================
 *
 * @author     hahawen(大龄青年) 
 * @since      2004-12-04
 * @copyright  Copyright (c) 2004, NxCoder Group
 *
 *=========================================================
 */
/**
 * abstract class SimpleDocumentBase
 * base class for xml file parse
 * all this pachage's is work for xml file, and method is action as DOM.
 *
 * 1\ add/update/remove data of xml file.
 * 2\ explode data to array.
 * 3\ rebuild xml file
 *
 * @package SmartWeb.common.xml
 * @abstract
 * @version 1.0
 */
abstract class SimpleDocumentBase
{
 private $nodeTag = null;
 private $attributes = array();
 private $values = array();
 private $nodes = array();
    function __construct($nodeTag)
    {
        $this->nodeTag = $nodeTag;
    }
    public function getNodeTag()
    {
     return $this->nodeTag;
    }
    public function setValues($values){
     $this->values = $values;
    }
    public function setValue($name, $value)
    {
     $this->values[$name] = $value;
    }
    public function getValue($name=null)
    {
     return $name==null? $this->values: $this->values[$name];
    }
    public function removeValue($name)
    {
     unset($this->values["$name"]);
    }
    public function setAttributes($attributes){
        $this->attributes = $attributes;
    }
    public function setAttribute($name, $value)
    {
     $this->attributes[$name] = $value;
    }
    public function getAttribute($name=null)
    {
        return $name==null? $this->attributes: $this->attributes[$name];
    }
    public function removeAttribute($name)
    {
     unset($this->attributes["$name"]);
    }
    public function getNodesSize()
    {
        return sizeof($this->nodes);
    }
    protected function setNode($name, $nodeId)
    {
     $this->nodes[$name] = $nodeId;
    }
    public abstract function createNode($name, $attributes);
    public abstract function removeNode($name);
    public abstract function getNode($name=null);
    protected function getNodeId($name=null)
    {
     return $name==null? $this->nodes: $this->nodes[$name];
    }
    protected function createNodeByName($rootNodeObj, $name, $attributes, $pId)
    {
        $tmpObject = $rootNodeObj->createNodeObject($pId, $name, $attributes);
        $key = isset($attributes[id])? $name.'_'.$attributes[id]: $name.'_'.$this->getNodesSize();
        $this->setNode($key, $tmpObject->getSeq());
     return $tmpObject;
    }
    protected function removeNodeByName($rootNodeObj, $name)
    {
        $rootNodeObj->removeNodeById($this->getNodeId($name));
        if(sizeof($this->nodes)==1)
            $this->nodes = array();
     else
      unset($this->nodes[$name]);
    }
    protected function getNodeByName($rootNodeObj, $name=null)
    {
     if($name==null)
     {
            $tmpList = array();
            $tmpIds = $this->getNodeId();
            foreach($tmpIds as $key=>$id)
             $tmpList[$key] = $rootNodeObj->getNodeById($id);
            return $tmpList;
     }
     else
     {
      $id = $this->getNodeId($name);
      if($id===null)
      {
             $tmpIds = $this->getNodeId();
             foreach($tmpIds as $tkey=>$tid)
             {
              if(strpos($key, $name)==0)
              {
               $id = $tid;
               break;
              }
             }
      }
      return $rootNodeObj->getNodeById($id);
     }
    }
    public function findNodeByPath($path)
    {
     $pos = strpos($path, '|');
     if($pos<=0)
     {
      return $this->getNode($path);
        }
        else
        {
         $tmpObj = $this->getNode(substr($path, 0, $pos));
         return is_object($tmpObj)? $tmpObj->findNodeByPath(substr($path, $pos+1)): null;
        }
    }
    public function getSaveData()
    {
        $data = $this->values;
        if(sizeof($this->attributes)>0)
         $data[attrs] = $this->attributes;
        $nodeList = $this->getNode();
        if($nodeList==null)
         return $data;
        foreach($nodeList as $key=>$node)
        {
         $data[$key] = $node->getSaveData();
        }
     return $data;
    }
    public function getSaveXml($level=0)
    {
     $prefixSpace = str_pad("", $level, "\t");
     $str = "$prefixSpace<$this->nodeTag";
        foreach($this->attributes as $key=>$value)
         $str .= " $key=\"$value\"";
        $str .= ">\r\n";
        foreach($this->values as $key=>$value){
            if(is_array($value))
            {
                $str .= "$prefixSpace\t<$key";
                foreach($value[attrs] as $attkey=>$attvalue)
                 $str .= " $attkey=\"$attvalue\"";
                $tmpStr = $value[value];
            }
            else
            {
             $str .= "$prefixSpace\t<$key";
             $tmpStr = $value;
            }
            $tmpStr = trim(trim($tmpStr, "\r\n"));
            $str .= ($tmpStr===null || $tmpStr==="")? " />\r\n": ">$tmpStr</$key>\r\n";
        }
        foreach($this->getNode() as $node)
         $str .= $node->getSaveXml($level+1)."\r\n";
     $str .= "$prefixSpace</$this->nodeTag>";
     return $str;
    }
    function __destruct()
    {
     unset($this->nodes, $this->attributes, $this->values);
    }
}
?>
     
 


文件:SimpleDocumentRoot.php

<?php
/**
 *=========================================================
 *
 * @author     hahawen(大龄青年) 
 * @since      2004-12-04
 * @copyright  Copyright (c) 2004, NxCoder Group
 *
 *=========================================================
 */
/**
 * class SimpleDocumentRoot
 * xml root class, include values/attributes/subnodes.
 * all this pachage's is work for xml file, and method is action as DOM.
 *
 * @package SmartWeb.common.xml
 * @version 1.0
 */
class SimpleDocumentRoot extends SimpleDocumentBase
{
 private $prefixStr = '<?xml version="1.0" encoding="utf-8" ?>';
 private $nodeLists = array();
 function __construct($nodeTag)
 {
        parent::__construct($nodeTag);
 }
    public function createNodeObject($pNodeId, $name, $attributes)
    {
     $seq = sizeof($this->nodeLists);
     $tmpObject = new SimpleDocumentNode($this, $pNodeId, $name, $seq);
     $tmpObject->setAttributes($attributes);
     $this->nodeLists[$seq] = $tmpObject;
     return $tmpObject;
    }
    public function removeNodeById($id)
    {
        if(sizeof($this->nodeLists)==1)
            $this->nodeLists = array();
     else
      unset($this->nodeLists[$id]);
    }
    public function getNodeById($id)
    {
     return $this->nodeLists[$id];
    }
    public function createNode($name, $attributes)
    {
        return $this->createNodeByName($this, $name, $attributes, -1);
    }
    public function removeNode($name)
    {
        return $this->removeNodeByName($this, $name);
    }
    public function getNode($name=null)
    {
        return $this->getNodeByName($this, $name);
    }
    public function getSaveXml()
    {
     $prefixSpace = "";
     $str = $this->prefixStr."\r\n";
     return $str.parent::getSaveXml(0);
    }
}
?>
     
 
  
  文件:SimpleDocumentNode.php


<?php
/**
 *=========================================================
 *
 * @author     hahawen(大龄青年) 
 * @since      2004-12-04
 * @copyright  Copyright (c) 2004, NxCoder Group
 *
 *=========================================================
 */
/**
 * class SimpleDocumentNode
 * xml Node class, include values/attributes/subnodes.
 * all this pachage's is work for xml file, and method is action as DOM.
 *
 * @package SmartWeb.common.xml
 * @version 1.0
 */
class SimpleDocumentNode extends SimpleDocumentBase
{
 private $seq = null;
 private $rootObject = null;
    private $pNodeId = null;
    function __construct($rootObject, $pNodeId, $nodeTag, $seq)
    {
     parent::__construct($nodeTag);
        $this->rootObject = $rootObject;
        $this->pNodeId = $pNodeId;
        $this->seq = $seq;
    }
    public function getPNodeObject()
    {
     return ($this->pNodeId==-1)? $this->rootObject: $this->rootObject->getNodeById($this->pNodeId);
    }
    public function getSeq(){
     return $this->seq;
    }
    public function createNode($name, $attributes)
    {
        return $this->createNodeByName($this->rootObject, $name, $attributes, $this->getSeq());
    }
    public function removeNode($name)
    {
        return $this->removeNodeByName($this->rootObject, $name);
    }
    public function getNode($name=null)
    {
        return $this->getNodeByName($this->rootObject, $name);
    }
}
?>
     
 


下面是例子运行对结果:

  下面是通过函数getSaveData()返回的整个xml数据的数组


Array
(
    [name] => 华联
    [address] => 北京长安街-9999号
    [desc] => 连锁超市
    [cat_food] => Array
        (
            [attrs] => Array
                (
                    [id] => food
                )
            [goods_food11] => Array
                (
                    [name] => food11
                    [price] => 12.90
                    [attrs] => Array
                        (
                            [id] => food11
                        )
                )
            [goods_food12] => Array
                (
                    [name] => food12
                    [price] => 22.10
                    [desc] => Array
                        (
                            [value] => 好东西推荐
                            [attrs] => Array
                                (
                                    [creator] => hahawen
                                )
                        )
                    [attrs] => Array
                        (
                            [id] => food12
                        )
                )
        )
    [cat_1] => Array
        (
            [goods_tel21] => Array
                (
                    [name] => tel21
                    [price] => 1290
                    [attrs] => Array
                        (
                            [id] => tel21
                        )
                )
        )
    [cat_coat] => Array
        (
            [attrs] => Array
                (
                    [id] => coat
                )
            [goods_coat31] => Array
                (
                    [name] => coat31
                    [price] => 112
                    [attrs] => Array
                        (
                            [id] => coat31
                        )
                )
            [goods_coat32] => Array
                (
                    [name] => coat32
                    [price] => 45
                    [attrs] => Array
                        (
                            [id] => coat32
                        )
                )
        )
    [special_hot] => Array
        (
            [attrs] => Array
                (
                    [id] => hot
                )
            [goods_0] => Array
                (
                    [name] => hot41
                    [price] => 99
                )
        )
)
 

  下面是通过setValue()函数,给给根节点添加信息,添加后显示出结果xml文件的内容


<?xml version="1.0" encoding="GB2312" ?>
<shop>
 <name>华联</name>
 <address>北京长安街-9999号</address>
 <desc>连锁超市</desc>
 <telphone>123456789</telphone>
 <cat id="food">
  <goods id="food11">
   <name>food11</name>
   <price>12.90</price>
  </goods>
  <goods id="food12">
   <name>food12</name>
   <price>22.10</price>
   <desc creator="hahawen">好东西推荐</desc>
  </goods>
 </cat>
 <cat>
  <goods id="tel21">
   <name>tel21</name>
   <price>1290</price>
  </goods>
 </cat>
 <cat id="coat">
  <goods id="coat31">
   <name>coat31</name>
   <price>112</price>
  </goods>
  <goods id="coat32">
   <name>coat32</name>
   <price>45</price>
  </goods>
 </cat>
 <special id="hot">
  <goods>
   <name>hot41</name>
   <price>99</price>
  </goods>
 </special>
</shop>
 


下面是通过getNode()函数,返回某一个分类下的所有商品的信息商品名:

food11Array
(
    [name] => food11
    [price] => 12.90
)
Array
(
    [id] => food11
)
商品名:food12Array
(
    [name] => food12
    [price] => 22.10
    [desc] => Array
        (
            [value] => 好东西推荐
            [attrs] => Array
                (
                    [creator] => hahawen
                )
        )
)
Array
(
    [id] => food12
)
 
  下面是通过findNodeByPath()函数,返回某一商品的信息商品名:
food11Array
(
    [name] => food11
    [price] => 12.90
)
Array
(
    [id] => food11
)
     
 

  下面是通过setValue()函数,给商品"food11"添加属性, 然后显示添加后的结果

<?xml version="1.0" encoding="GB2312" ?>
<shop>
 <name>华联</name>
 <address>北京长安街-9999号</address>
 <desc>连锁超市</desc>
 <telphone>123456789</telphone>
 <cat id="food">
  <goods id="food11">
   <name>food11</name>
   <price>12.90</price>
   <leaveword author="hahawen" date="2004-12-05">这个商品不错</leaveword>
  </goods>
  <goods id="food12">
   <name>food12</name>
   <price>22.10</price>
   <desc creator="hahawen">好东西推荐</desc>
  </goods>
 </cat>
 <cat>
  <goods id="tel21">
   <name>tel21</name>
   <price>1290</price>
  </goods>
 </cat>
 <cat id="coat">
  <goods id="coat31">
   <name>coat31</name>
   <price>112</price>
  </goods>
  <goods id="coat32">
   <name>coat32</name>
   <price>45</price>
  </goods>
 </cat>
 <special id="hot">
  <goods>
   <name>hot41</name>
   <price>99</price>
  </goods>
 </special>
</shop>
 

  下面是通过removeValue()/removeAttribute()函数,给商品"food11"改变和删除属性, 然后显示操作后的结果

<?xml version="1.0" encoding="GB2312" ?>
<shop>
 <name>华联</name>
 <address>北京长安街-9999号</address>
 <desc>连锁超市</desc>
 <telphone>123456789</telphone>
 <cat id="food">
  <goods id="food11">
   <name>food11</name>
   <price>12.90</price>
   <leaveword author="hahawen" date="2004-12-05">这个商品不错</leaveword>
  </goods>
  <goods id="food12">
   <name>new food12</name>
   <price>22.10</price>
  </goods>
 </cat>
 <cat>
  <goods id="tel21">
   <name>tel21</name>
   <price>1290</price>
  </goods>
 </cat>
 <cat id="coat">
  <goods id="coat31">
   <name>coat31</name>
   <price>112</price>
  </goods>
  <goods id="coat32">
   <name>coat32</name>
   <price>45</price>
  </goods>
 </cat>
 <special id="hot">
  <goods>
   <name>hot41</name>
   <price>99</price>
  </goods>
 </special>
</shop>
 


下面是通过createNode()函数,添加商品, 然后显示添加后的结果

<?xml version="1.0" encoding="GB2312" ?>
<shop>
 <name>华联</name>
 <address>北京长安街-9999号</address>
 <desc>连锁超市</desc>
 <telphone>123456789</telphone>
 <cat id="food">
  <goods id="food11">
   <name>food11</name>
   <price>12.90</price>
   <leaveword author="hahawen" date="2004-12-05">这个商品不错</leaveword>
  </goods>
  <goods id="food12">
   <name>new food12</name>
   <price>22.10</price>
  </goods>
  <goods id="food13">
   <name>food13</name>
   <price>100</price>
  </goods>
 </cat>
 <cat>
  <goods id="tel21">
   <name>tel21</name>
   <price>1290</price>
  </goods>
 </cat>
 <cat id="coat">
  <goods id="coat31">
   <name>coat31</name>
   <price>112</price>
  </goods>
  <goods id="coat32">
   <name>coat32</name>
   <price>45</price>
  </goods>
 </cat>
 <special id="hot">
  <goods>
   <name>hot41</name>
   <price>99</price>
  </goods>
 </special>
</shop>
 

  下面是通过removeNode()函数,删除商品, 然后显示删除后的结果

<?xml version="1.0" encoding="GB2312" ?>
<shop>
 <name>华联</name>
 <address>北京长安街-9999号</address>
 <desc>连锁超市</desc>
 <telphone>123456789</telphone>
 <cat id="food">
  <goods id="food11">
   <name>food11</name>
   <price>12.90</price>
   <leaveword author="hahawen" date="2004-12-05">这个商品不错</leaveword>
  </goods>
  <goods id="food13">
   <name>food13</name>
   <price>100</price>
  </goods>
 </cat>
 <cat>
  <goods id="tel21">
   <name>tel21</name>
   <price>1290</price>
  </goods>
 </cat>
 <cat id="coat">
  <goods id="coat31">
   <name>coat31</name>
   <price>112</price>
  </goods>
  <goods id="coat32">
   <name>coat32</name>
   <price>45</price>
  </goods>
 </cat>
 <special id="hot">
  <goods>
   <name>hot41</name>
   <price>99</price>
  </goods>
 </special>
</shop>

 

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
과대 광고 : 오늘 PHP의 역할을 평가합니다과대 광고 : 오늘 PHP의 역할을 평가합니다Apr 12, 2025 am 12:17 AM

PHP는 현대적인 프로그래밍, 특히 웹 개발 분야에서 강력하고 널리 사용되는 도구로 남아 있습니다. 1) PHP는 사용하기 쉽고 데이터베이스와 완벽하게 통합되며 많은 개발자에게 가장 먼저 선택됩니다. 2) 동적 컨텐츠 생성 및 객체 지향 프로그래밍을 지원하여 웹 사이트를 신속하게 작성하고 유지 관리하는 데 적합합니다. 3) 데이터베이스 쿼리를 캐싱하고 최적화함으로써 PHP의 성능을 향상시킬 수 있으며, 광범위한 커뮤니티와 풍부한 생태계는 오늘날의 기술 스택에 여전히 중요합니다.

PHP의 약한 참고 자료는 무엇이며 언제 유용합니까?PHP의 약한 참고 자료는 무엇이며 언제 유용합니까?Apr 12, 2025 am 12:13 AM

PHP에서는 약한 참조가 약한 회의 클래스를 통해 구현되며 쓰레기 수집가가 물체를 되 찾는 것을 방해하지 않습니다. 약한 참조는 캐싱 시스템 및 이벤트 리스너와 같은 시나리오에 적합합니다. 물체의 생존을 보장 할 수 없으며 쓰레기 수집이 지연 될 수 있음에 주목해야합니다.

PHP의 __invoke 마법 방법을 설명하십시오.PHP의 __invoke 마법 방법을 설명하십시오.Apr 12, 2025 am 12:07 AM

\ _ \ _ 호출 메소드를 사용하면 객체를 함수처럼 호출 할 수 있습니다. 1. 객체를 호출 할 수 있도록 메소드를 호출하는 \ _ \ _ 정의하십시오. 2. $ obj (...) 구문을 사용할 때 PHP는 \ _ \ _ invoke 메소드를 실행합니다. 3. 로깅 및 계산기, 코드 유연성 및 가독성 향상과 같은 시나리오에 적합합니다.

동시성에 대해 PHP 8.1의 섬유를 설명하십시오.동시성에 대해 PHP 8.1의 섬유를 설명하십시오.Apr 12, 2025 am 12:05 AM

섬유는 PHP8.1에 도입되어 동시 처리 기능을 향상시켰다. 1) 섬유는 코 루틴과 유사한 가벼운 동시성 모델입니다. 2) 개발자는 작업의 실행 흐름을 수동으로 제어 할 수 있으며 I/O 집약적 작업을 처리하는 데 적합합니다. 3) 섬유를 사용하면보다 효율적이고 반응이 좋은 코드를 작성할 수 있습니다.

PHP 커뮤니티 : 자원, 지원 및 개발PHP 커뮤니티 : 자원, 지원 및 개발Apr 12, 2025 am 12:04 AM

PHP 커뮤니티는 개발자 성장을 돕기 위해 풍부한 자원과 지원을 제공합니다. 1) 자료에는 공식 문서, 튜토리얼, 블로그 및 Laravel 및 Symfony와 같은 오픈 소스 프로젝트가 포함됩니다. 2) 지원은 StackoverFlow, Reddit 및 Slack 채널을 통해 얻을 수 있습니다. 3) RFC에 따라 개발 동향을 배울 수 있습니다. 4) 적극적인 참여, 코드에 대한 기여 및 학습 공유를 통해 커뮤니티에 통합 될 수 있습니다.

PHP vs. Python : 차이점 이해PHP vs. Python : 차이점 이해Apr 11, 2025 am 12:15 AM

PHP와 Python은 각각 고유 한 장점이 있으며 선택은 프로젝트 요구 사항을 기반으로해야합니다. 1.PHP는 간단한 구문과 높은 실행 효율로 웹 개발에 적합합니다. 2. Python은 간결한 구문 및 풍부한 라이브러리를 갖춘 데이터 과학 및 기계 학습에 적합합니다.

PHP : 죽어 가거나 단순히 적응하고 있습니까?PHP : 죽어 가거나 단순히 적응하고 있습니까?Apr 11, 2025 am 12:13 AM

PHP는 죽지 않고 끊임없이 적응하고 진화합니다. 1) PHP는 1994 년부터 새로운 기술 트렌드에 적응하기 위해 여러 버전 반복을 겪었습니다. 2) 현재 전자 상거래, 컨텐츠 관리 시스템 및 기타 분야에서 널리 사용됩니다. 3) PHP8은 성능과 현대화를 개선하기 위해 JIT 컴파일러 및 기타 기능을 소개합니다. 4) Opcache를 사용하고 PSR-12 표준을 따라 성능 및 코드 품질을 최적화하십시오.

PHP의 미래 : 적응 및 혁신PHP의 미래 : 적응 및 혁신Apr 11, 2025 am 12:01 AM

PHP의 미래는 새로운 기술 트렌드에 적응하고 혁신적인 기능을 도입함으로써 달성 될 것입니다. 1) 클라우드 컴퓨팅, 컨테이너화 및 마이크로 서비스 아키텍처에 적응, Docker 및 Kubernetes 지원; 2) 성능 및 데이터 처리 효율을 향상시키기 위해 JIT 컴파일러 및 열거 유형을 도입합니다. 3) 지속적으로 성능을 최적화하고 모범 사례를 홍보합니다.

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25 : Myrise에서 모든 것을 잠금 해제하는 방법
4 몇 주 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

MinGW - Windows용 미니멀리스트 GNU

MinGW - Windows용 미니멀리스트 GNU

이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

SublimeText3 Linux 새 버전

SublimeText3 Linux 새 버전

SublimeText3 Linux 최신 버전

DVWA

DVWA

DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

Atom Editor Mac 버전 다운로드

Atom Editor Mac 버전 다운로드

가장 인기 있는 오픈 소스 편집기

안전한 시험 브라우저

안전한 시험 브라우저

안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.