当前位置:编程学习 > php >>

php dom增加xml节点函数

php教程 dom增加xml节点函数

    function: addcomment
   
    adds a comment.
   
    parameters:
      $data - associative array of data, must contain 'name', 'website', 'comment', 'date', 'user_ip', 'user_agent', and 'spam'.
     
    returns:
      id of the new comment.
  
   <?xml version="1.0" encoding="utf-8"?>
<!doctype messages [
<!element messages (message)*>
<!element message (name , website? , comment , date , user_ip? , user_agent? , spam)>
]>
<messages>
</messages>
  */
  public function addcomment($data) {
    $xml = new simplexmlelement($this->getcontents(true));
    $message = $xml->addchild('message');
    $id = $this->generateid();
    $message->addattribute('mid', $id);
    foreach ($data as $key => $value) {
      $message->addchild($key, htmlspecialchars($value, ent_quotes));
    }
    $this->putcontents($xml->asxml());
   
    return $id;
  }
补充:Php教程,XML应用 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,