【发布时间】:2011-12-24 14:24:16
【问题描述】:
我的 XML 文档包含以下节点:
1 个 macbook air 和 4 个 ipod
我的问题是如何读取“变量”值(1 和 4)并用 php 回显它们。
【问题讨论】:
我的 XML 文档包含以下节点:
1 个 macbook air 和 4 个 ipod
我的问题是如何读取“变量”值(1 和 4)并用 php 回显它们。
【问题讨论】:
您应该使用simplexml XML 解析器和一些正则表达式。
<?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]);
【讨论】: