如何使用 php 从名称中数字递增的 xml 节点读取值


How to read values from xml nodes with names having increasing numer in it using php

我有一个xml,其中包含以下序列中的节点。

<text_value0>text0</text_value0>
<text_value1>text1</text_value1>
<text_value2>text2</text_value2>.............

您能否建议如何在不读取每个标签的情况下从这些类型的节点读取(解析)值,可能是通过使用任何循环或其他东西通过代码获取所有值。

试试这个:

<?php 
$myXMLData ="<?xml version='1.0' encoding='UTF-8'?>
<note>
<text_value0>text0</text_value0>
<text_value1>text1</text_value1>
<text_value2>text2</text_value2>
<text_value3>text3</text_value3>
</note>";
$xml = simplexml_load_string($myXMLData);
foreach ($xml as $text){
  echo $text."<br>";
 }
?>