Php 读取XML节点中的值
我的XML文档包含以下节点: 1台macbook air和4台iPod 我的问题是如何读取“变量”值(1和4)并用php进行回显。您应该使用XML解析器和一些正则表达式Php 读取XML节点中的值,php,xml,Php,Xml,我的XML文档包含以下节点: 1台macbook air和4台iPod 我的问题是如何读取“变量”值(1和4)并用php进行回显。您应该使用XML解析器和一些正则表达式 <?php $string = <<<XML <?xml version='1.0'?> <document> <description>1 macbook air and 4 ipods</description> </document>
<?php
$string = <<<XML
<?xml version='1.0'?>
<document>
<description>1 macbook air and 4 ipods</description>
</document>
XML;
$xml = simplexml_load_string($string);
$description = $xml->description;
preg_match('|(\d+) macbook air and (\d+) ipods|', $description, $match);
print_r($match[1] . ' ');
print_r($match[2]);
描述;
preg|u match(“|(\d+)macbook air和(\d+)iPod,$description,$match);
打印($match[1].');
打印($match[2]);