我们在运用
PHP XMLReader的代码示例如下:
- ?PHP
-
header("Content-type:text/html;
Charset=utf-8"); -
$url = "http://www.google.com/
ig/api?weather=shenzhen"; - // 加载XML内容
- $xml = new XMLReader();
- $xml->open($url);
- $condition = '';
- $temp_c = '';
- while ($xml->read()) {
-
// echo $xml->name, "==>",
$xml->depth, "br>"; - if (!empty($condition)
&& !empty($temp_c)) { - break;
- }
-
if ($xml->name == 'condition'
&& empty($condition)) { - // 取第一个condition
- $condition = $xml->getAttribute('data');
- }
-
if ($xml->name == 'temp_c' &&
empty($temp_c)) { - // 取第一个temp_c
- $temp_c = $xml->getAttribute('data');
- }
- $xml->read();
- }
- $xml->close();
- echo '天气:', $condition, ' br />';
- echo '温度:', $temp_c, ' br />';
我们只是需要运用PHP XMLReader取第一个condition和第一个temp_c,于是遍历所有的节点,将遇到的第一个condition和第一个temp_c写入变量,最后输出。

Heiße KI -Werkzeuge

Undresser.AI Undress
KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover
Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool
Ausziehbilder kostenlos

Clothoff.io
KI-Kleiderentferner

AI Hentai Generator
Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

Heiße Werkzeuge

Dreamweaver CS6
Visuelle Webentwicklungstools

Sicherer Prüfungsbrowser
Safe Exam Browser ist eine sichere Browserumgebung für die sichere Teilnahme an Online-Prüfungen. Diese Software verwandelt jeden Computer in einen sicheren Arbeitsplatz. Es kontrolliert den Zugriff auf alle Dienstprogramme und verhindert, dass Schüler nicht autorisierte Ressourcen nutzen.

EditPlus chinesische Crack-Version
Geringe Größe, Syntaxhervorhebung, unterstützt keine Code-Eingabeaufforderungsfunktion

Senden Sie Studio 13.0.1
Leistungsstarke integrierte PHP-Entwicklungsumgebung

WebStorm-Mac-Version
Nützliche JavaScript-Entwicklungstools