1

これは私のreg.xmlです:

<childrens>
<child_4 entity_id="4" value="Activities" parent_id="2">
    <child_10066 entity_id="10066" value="Physical1" parent_id="4">
    <child_10067 entity_id="10067" value="Cricket" parent_id="10066">
        <child_10068 entity_id="10068" value="One Day" parent_id="10067"/>
    </child_10067>
    </child_10066>
</child_4>
<child_4331 entity_id="4331" value="Region" parent_id="2">
    <child_5069 entity_id="5069" value="Irungattukottai" parent_id="4331"/>
</child_4331>
</childrens>

これは私のproduct.xmlファイルです:

<products>
  <product_id value="1">
    <tab_id value="351">
      <tab_name value="test1"/>
      <region_timezone value="1"/>
      <registrationstatus value="2"/>
      <eventstatus value="2"/>
      <dist_activity value="5"/>
      <dist_activity value="10068"/>
      <dist_activity value="10070"/>
      <dist_region value="5069"/>
      <dist_region value="5069"/>
      <dist_region value="5069"/>
    </tab_id>
  </product_id>
  <product_id value="2">
    <tab_id value="352">
      <tab_name value="test2"/>
      <region_timezone value="1"/>
      <registrationstatus value="2"/>
      <eventstatus value="2"/>
      <dist_activity value="5"/>
      <dist_activity value="10069"/>
      <dist_activity value="10070"/>
      <dist_region value="4457"/>
      <dist_region value="7140"/>
      <dist_region value="5069"/>
   </tab_id>
  </product_id>
</products>

これは私の試みです:

<?php
 $abc= $_POST['name'];
 list($first,$second) = explode('in',$abc);

 $text1[]=$first;
 $text2[]=$second;
 foreach($text1 as $event)
{
$event;
}
foreach($text2 as $region1)
{
$region1;
}
$r = file_get_contents('reg.xml');
$p = file_get_contents('product.xml');

$region = simplexml_load_string($r);
$product = simplexml_load_string($p);

list($entity) = $region->xpath("//*[@value='$event']/@entity_id");
$entity=(string)$entity;
echo "event:- $event, Region:- $region1, entity:- $entity";
 ?>

これは私のHTMLファイルです:

<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
    </script>
    <script>
    $(function(){
$("#filter").click(function(){
    var name = $('#select').val();
    alert(name);
    $.ajax({
        type: "POST",
        data: {"name":name} ,
        url: "array.php",
        async: false,       
        success: function(result) { 
        alert(result);
        $("#result").text(result);
        } 
    });   


    });
});
    </script>
</head>
<body>
    <input type="text" id="select">
    <input  type="button" id="filter" name="button" value="Search">
    <div id="result">
    </div>
</body>
</html>

この値をテキストボックスに入力します。 One Day in Irungattukottai
このコードを試しましたが、機能せず、$entity. eg:- = value を
手動で設定しようとすると、うまく いくので、これで私を助けてください。ありがとう。$event$event"One Day"
foreach

4

1 に答える 1

0

foreach コードは非常に奇妙に見えます。そこで何をしようとしているのかわかりません。しかし、実際の問題はexplode()にあると思います。これは、「in」という単語の両側のスペースを見ていないため、One Dayは最後にスペースがあり、イルンガットコッタイは先頭にスペースがあります。

これを修正するには、explode() にスペースを含めるか、生成される 2 つの文字列に対して trim() を使用します。

于 2013-03-28T12:47:29.117 に答える