这是我的xml文件: -
<products>
<product_id value="1">
<tab_id value="351">
<dist_activity value="10068"/>
<dist_activity value="10070"/>
<individual_strdt value="2013-01-14 20:35:00"/>
</tab_id>
</product_id>
<product_id value="2">
<tab_id value="352">
<dist_activity value="10069"/>
<dist_activity value="10070"/>
<individual_strdt value="2013-02-14 20:39:00"/>
</tab_id>
</product_id>
</products>
这是我的代码: -
<?php
$abc="10068 in 2013-02-14 20:39:00";
list($one,$two)=explode(' in ',$abc);
$text1[]=$one;
$text2[]=$two;
foreach($text1 as $activity)
{
$actvitiy;
}
foreach($text2 as $date)
{
$date;
}
$p = file_get_contents('product.xml');
$product = simplexml_load_string($p);
list($activity_id) = $product->xpath("//dist_activity['$actvitiy'] | //individual_strdt['$date']/ancestor::product_id/@value");
$activity_id = (string) $activity_id;
?>
<script language="javascript">
alert('<?= $activity_id ?>')
</script>
<?php
if (strlen(trim($activity_id))==0)
{
echo $activity.'&'.$date.' Region Not Match';
exit;
} //check the $entity in product.xml
echo "id:- $activity_id";
?>
这里我在$abc
中有一个字符串
我试图用in
explo爆炸它们
并存入两个差异var
是这样的回报:
$one = 10068
$two = 2013-02-14 20:39:00
尝试签入product.xml
文件
$ {1}值<dist_activity>
<individual_strdt>
的$ 2值
两者都匹配然后返回父元素属性值,如<product_id>
值1
(一个是输出)
的查询: -
现在的问题是在$ abc字符串中,两个值都是diff。元素子值10068
是<product_id>
1
子元素,2013-02-14 20:39:00
是<product_id>
2
子元素。
现在在这种情况下消息soud被打印两个值都不匹配
但它不能正常显示product_id值1
答案 0 :(得分:0)
可能是你需要的:
list($activity_id) = $product->xpath("//dist_activity[@value = '$actvitiy' ] | //individual_strdt[ @value = '$date']/ancestor::product_id/@value");