2014-06-06 1 views
0
여기

내 코드입니다 : (. 내 PHP 버전은 5.5.10이다) 이PHP에서 XML 파일의 두 문자열을 비교하는 방법은 무엇입니까?

여기
<?php 
# erprate # 
$erprate_raw = simplexml_load_file("trafficinfo/ERPRateSet.xml"); 
$erprate_file = simplexml_load_file("trafficinfo/ERPRateSet.xml")->entry; 
$erprate_namespace = $erprate_file->getNameSpaces(true); 
# erprate # 
     for ($a = 0; $a < ($erprate_file->count()); $a++) { 
      $awesome = 1; 
      $zoneid = $erprate_raw->entry[$a]->content->children($erprate_namespace['m'])->properties->children($erprate_namespace['d'])->ZoneID; 
      if ($a > 0) { 
       for ($b = 0; $b < $a; $b++) { 
        // echo $a . " " . $b . '<br>'; 
        $zoneidb = $erprate_raw->entry[$b]->content->children($erprate_namespace['m'])->properties->children($erprate_namespace['d'])->ZoneID; 
        if ($zoneid == $zoneidb) { 
         $awesome = 2; 
         break; 
        } 
       } 
      } 
      if ($awesome == 1) { 
       echo $zoneid . "<br>"; 
      } 
     } 
?> 

가 (매우 작은 부분) 내 XML 파일입니다 (원래의 코드는 60000+ 자입니다)

<?xml version="1.0" encoding="utf-8" standalone="yes"?> 
<feed xml:base="http://datamall.mytransport.sg/LTAoDataService.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom"> 
    <title type="text">ERPRateSet</title> 
    <id>http://datamall.mytransport.sg/ltaodataservice.svc/ERPRateSet</id> 
    <updated>2012-02-10T09:25:04Z</updated> 
    <link rel="self" title="ERPRateSet" href="ERPRateSet" /> 
    <entry> 
    <id>http://datamall.mytransport.sg/LTAoDataService.svc/ERPRateSet(236026)</id> 
    <title type="text">Passenger Cars/Light Goods Vehicles/Taxis</title> 
    <summary type="text">VCC Type: Passenger Cars/Light Goods Vehicles/Taxis Zone ID:CT4 Day Type: Weekdays Time: 07:00 - 07:05 Amount: 0.5</summary> 
    <updated>2012-02-10T09:25:04Z</updated> 
    <author> 
     <name /> 
    </author> 
    <link rel="edit" title="ERPRate" href="ERPRateSet(236026)" /> 
    <category term="LTAModel.ERPRate" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> 
    <content type="application/xml"> 
     <m:properties> 
     <d:ERPID m:type="Edm.Int32">236026</d:ERPID> 
     <d:VCCType>Passenger Cars/Light Goods Vehicles/Taxis</d:VCCType> 
     <d:DayType>Weekdays</d:DayType> 
     <d:EffectiveDate m:type="Edm.DateTime">2012-02-06T00:00:00</d:EffectiveDate> 
     <d:ZoneID>CT4</d:ZoneID> 
     <d:ChargeAmount m:type="Edm.Double">0.5</d:ChargeAmount> 
     <d:StartTime>07:00</d:StartTime> 
     <d:EndTime>07:03883</d:EndTime> 
     <d:Summary>VCC Type: Passenger Cars/Light Goods Vehicles/Taxis Zone ID:CT4 Day Type: Weekdays Time: 07:00 - 07:05 Amount: 0.5</d:Summary> 
     <d:CreateDate m:type="Edm.DateTime">2012-02-09T16:34:31.733</d:CreateDate> 
     </m:properties> 
    </content> 
    </entry> 
    <entry> 
    <id>http://datamall.mytransport.sg/LTAoDataService.svc/ERPRateSet(236027)</id> 
    <title type="text">Passenger Cars/Light Goods Vehicles/Taxis</title> 
    <summary type="text">VCC Type: Passenger Cars/Light Goods Vehicles/Taxis Zone ID:BKE Day Type: Weekdays Time: 07:00 - 07:30 Amount: 0</summary> 
    <updated>2012-02-10T09:25:04Z</updated> 
    <author> 
     <name /> 
    </author> 
    <link rel="edit" title="ERPRate" href="ERPRateSet(236027)" /> 
    <category term="LTAModel.ERPRate" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> 
    <content type="application/xml"> 
     <m:properties> 
     <d:ERPID m:type="Edm.Int32">236027</d:ERPID> 
     <d:VCCType>Passenger Cars/Light Goods Vehicles/Taxis</d:VCCType> 
     <d:DayType>Weekdays</d:DayType> 
     <d:EffectiveDate m:type="Edm.DateTime">2012-02-06T00:00:00</d:EffectiveDate> 
     <d:ZoneID>BKE</d:ZoneID> 
     <d:ChargeAmount m:type="Edm.Double">0</d:ChargeAmount> 
     <d:StartTime>07:00</d:StartTime> 
     <d:EndTime>07:30</d:EndTime> 
     <d:Summary>VCC Type: Passenger Cars/Light Goods Vehicles/Taxis Zone ID:BKE Day Type: Weekdays Time: 07:00 - 07:30 Amount: 0</d:Summary> 
     <d:CreateDate m:type="Edm.DateTime">2012-02-09T16:34:31.75</d:CreateDate> 
     </m:properties> 
    </content> 
    </entry> 
</feed> 

복제본이 어떻게 든 출력됩니다 ... 누군가가이 문제를 해결할 수 있습니까?

답변

0

이 문제를 해결해야합니다 : 당신이

+0

이 작동하지 않았다 비교하는 inexistent 인덱스에 액세스하려고하기 전에

for ($a = 0; $a < ($erprate_file->count()); $a++) 

더 나은 옵션은

for ($a = 0; $a < (count($erprate_file)-1); $a++) 

입니다 ... 여전히 똑같은 것이 출력되었습니다 ... – theroyalstudent

+0

출력에 대해 더 많이 말하십시오. – manespgav