PHP | Функция XMLReader close ()

Опубликовано: 20 Февраля, 2022

Функция XMLReader :: close () - это встроенная функция в PHP, которая используется для закрытия ввода объекта XMLReader, который в настоящее время анализируется.

Синтаксис:

 bool XMLReader :: close ( недействительно )

Параметры: эта функция не принимает никаких параметров.

Возвращаемое значение: эта функция возвращает ИСТИНА в случае успеха или ЛОЖЬ в случае неудачи.

Примеры ниже иллюстрируют функцию XMLReader :: close () в PHP:

Program 1:

  • data.xml
    <?xml version="1.0" encoding="utf-8"?>
    <root>
        <p> Hello world </p>
    </root>
  • index.php
    <?php
      
    // Create a new XMLReader instance
    $XMLReader = new XMLReader();
      
    // Open the XML file
    $XMLReader->open("data.xml");
      
    // Close the XML Reader before reading XML
    $XMLReader->close();
      
    // Move to the first node
    $XMLReader->read();
      
    // Read it as a string
    $string = $XMLReader->readString();
      
    // Output the string to the browser
    echo $string;
    ?>
  • Output:
    // Blank because we closed the input of the XMLReader before reading XML

Program 2:

  • data.xml
    <?xml version="1.0" encoding="utf-8"?>
    <body>
        <h1> GeeksforGeeks </h1>
    </body>
  • index.php
    <?php
      
    // Create a new XMLReader instance
    $XMLReader = new XMLReader();
      
    // Open the XML file
    $XMLReader->open("data.xml");
      
    // Move to the first node
    $XMLReader->read();
      
    // Read it as a string
    $string = $XMLReader->readString();
      
    // Output the string to the browser
    echo $string;
      
    // Close the XML Reader after reading XML
    $XMLReader->close();
    ?>
  • Output:
    GeeksforGeeks

Ссылка: https://www.php.net/manual/en/xmlreader.close.php

PHP