当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP XMLWriter endElement()用法及代码示例


XMLWriter::endElement()函数是PHP中的内置函数,用于结束使用XMLWriter::startElement()函数启动的当前元素。

用法:

bool XMLWriter::endElement( void )

参数:此函数不接受任何参数。



返回值:成功时返回TRUE,失败时返回FALSE。

以下示例说明了PHP中的XMLWriter::endElement()函数:

范例1:

<?php 
  
// Create a new XMLWriter instance 
$writer = new XMLWriter(); 
  
// Create the output stream as PHP 
$writer->openURI('php://output'); 
  
// Start the document 
$writer->startDocument('1.0', 'UTF-8'); 
  
// Start a element 
$writer->startElement('strong'); 
  
// Add value to the element 
$writer->text('GeeksforGeeks in bold.'); 
  
// End the element 
$writer->endElement(); 
  
// End the document 
$writer->endDocument(); 
?>

输出:

GeeksforGeeks in bold.

范例2:

<?php 
  
// Create a new XMLWriter instance 
$writer = new XMLWriter(); 
  
// Create the output stream as PHP 
$writer->openURI('php://output'); 
  
// Start the document 
$writer->startDocument('1.0', 'UTF-8'); 
  
// Start a element 
$writer->startElement('div'); 
  
// Write the attribute 
$writer->writeAttribute('style', 'color:red'); 
  
// Add value to the element 
$writer->text('Red GeeksforGeeks'); 
  
// End the element 
$writer->endElement(); 
  
// Start a element 
$writer->startElement('mark'); 
  
// Add value to the element 
$writer->text('Marked GeeksforGeeks'); 
  
// End the element 
$writer->endElement(); 
  
// End the document 
$writer->endDocument(); 
?>

输出:

参考: https://www.php.net/manual/en/function.xmlwriter-end-element.php




相关用法


注:本文由纯净天空筛选整理自gurrrung大神的英文原创作品 PHP | XMLWriter endElement() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。