Home >Backend Development >PHP Tutorial >PHP+XML缓存怎么快速读取指定的值

PHP+XML缓存怎么快速读取指定的值

WBOY
WBOYOriginal
2016-06-13 10:28:24727browse

PHP+XML缓存如何快速读取指定的值
用XML缓存
结构是

  -
  -
  1
  B007
 

  -
  2
  B001
 

  -
  3
  B000
 

  -
  4
  B004
 

  -
  5
  B003
 

  ..............
 



复制代码
数据比较多

现在我想快速找到
id=4的pd值
或者id=4下面的item的所有值
应该怎么写?

还有一个问题,xml可以支持动态读取值的吗?
比如a.xml?id=4
这类型的
可以吗?谢谢

是PHP的

------解决方案--------------------
参考:http://topic.csdn.net/u/20120521/03/527bc4d2-b4e0-4d6e-9ae4-021a675cfff5.html
------解决方案--------------------

PHP code
$xml=simplexml_load_file('bb.xml');foreach($xml->item as $v){      if($v->id==4) echo "id : $v->id<br>pd : $v->pd";}<br><font color="#e78608">------解决方案--------------------</font><br>xpath,还有其他答案吗。<br><br>
PHP code
[User:root Time:10:28:18 Path:/home/liangdong/php]$ php xpath.php pd B004[User:root Time:10:28:19 Path:/home/liangdong/php]$ cat xpath.php <?php $str = <<<EOF<channel>  <item>  <id>1</id>  <pd>B007</pd>  </item>  <item>  <id>2</id>  <pd>B001</pd>  </item>  <item>  <id>3</id>  <pd>B000</pd>  </item>  <item>  <id>4</id>  <pd>B004</pd>  </item>  <item>  <id>5</id>  <pd>B003</pd>  </item>  EOF;$xml = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOBLANKS);$res = $xml->xpath("/channel/item/id[text()=4]/parent::item/pd");foreach ($res as $node) {        echo $node->getName() . " " . $node->{0} . PHP_EOL;}?><div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn