2013-11-22 17 views
0

EDIT: я добавил весь код в конце этого сообщения. Мой код ниже работал нормально в PHP 5.3, но он возвращает пустые результаты в PHP 5.4. Что вызывает его?массив не работает после перехода на PHP5.4

Это код, я использую:

$xaxis=array(); 

    for ($i = 1; $i <= 3; $i++) { 
     $chachg_time = $xml->xpath("//ns:BulkData[ns:Name='ChannelChangeHistory.{$i}.ChannelChangeTime']/ns:Value"); 
     $chachg_time = $chachg_time[0]; 
     $xaxis[] = $chachg_time[0]; 
    }  

В PHP 5.3, я получаю следующий результат (который является то, что я ожидал):

Array 
(
    [0] => SimpleXMLElement Object 
     (
      [0] => 6 
     ) 

) 
Array 
(
    [0] => SimpleXMLElement Object 
     (
      [0] => 6 
     ) 

    [1] => SimpleXMLElement Object 
     (
      [0] => 5 
     ) 

) 
Array 
(
    [0] => SimpleXMLElement Object 
     (
      [0] => 6 
     ) 

    [1] => SimpleXMLElement Object 
     (
      [0] => 5 
     ) 

    [2] => SimpleXMLElement Object 
     (
      [0] => 3 
     ) 

) 

В PHP 5.4 Я получаю следующее:

Array 
(
    [0] => SimpleXMLElement Object 
     (
     ) 

) 
Array 
(
    [0] => SimpleXMLElement Object 
     (
     ) 

    [1] => SimpleXMLElement Object 
     (
     ) 

) 
Array 
(
    [0] => SimpleXMLElement Object 
     (
     ) 

    [1] => SimpleXMLElement Object 
     (
     ) 

    [2] => SimpleXMLElement Object 
     (
     ) 

) 

Вот исходный код workig с PHP 5.3 Версия

require_once ('jpgraph/src/jpgraph.php'); 
require_once ('jpgraph/src/jpgraph_line.php'); 
require_once ('jpgraph/src/jpgraph_scatter.php'); 
require_once ('jpgraph/src/jpgraph_date.php'); 


$dir = realpath(getcwd()); 
$pattern = '/\.(xml)$/'; // check only file with these ext.   
$newstamp = 0;    
$newname = ""; 

if ($handle = opendir($dir)) {    
     while (false !== ($fname = readdir($handle))) {    
     // Eliminate current directory, parent directory 
     if (preg_match('/^\.{1,2}$/',$fname)) continue;    
     // Eliminate other pages not in pattern    
     if (! preg_match($pattern,$fname)) continue;    
     $timedat = filemtime("$dir/$fname");    
     if ($timedat > $newstamp) { 
      $newstamp = $timedat; 
      $newname = $fname; 
      } 
     } 
     } 
closedir ($handle); 

$feed = file_get_contents($newname); 
$xml = new SimpleXmlElement($feed); 
$xml->registerXPathNamespace("ns", "urn:broadband-forum-org:ipdr:tr-232-1-0"); 

// RUN CHANNEL CHANGE HISTORY SCRIPT // 

     $yaxis=array(); 
     $xaxis=array(); 

     for ($i = 1; $i <= 32; $i++) { 
       $chachg_time = $xml->xpath("//ns:BulkData[ns:Name='InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_ATT_ChannelChangeHistory.{$i}.ChannelChangeTime']/ns:Value"); 
       $chachg_time = $chachg_time[0]; 
       if ($chachg_time == "") 
        { 
        break; 
        }  
       else { 

        $xaxis[] = date("M-d h:i:s A", strtotime($chachg_time[0])); 
        $ch = $xml->xpath("//ns:BulkData[ns:Name='InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_ATT_ChannelChangeHistory.{$i}.Channel']/ns:Value"); 
        $ch = $ch[0]; 
        $yaxis[]=$ch[0]; 
        } 
       }    
       foreach ($xaxis as $k => &$v) { 
        $a = (array)$v; 
        $v = $a[0]; 
       } 
       foreach ($yaxis as $s => &$t) { 
        $b = (array)$t; 
        $t = $b[0]; 
       } 



// Width and height of the graph 
$width = 1000; $height = 800; 

// Create a graph instance 
$graph = new Graph($width,$height); 

$graph->setMargin(50,50,40,200); 
// Specify what scale we want to use, 
// text = txt scale for the X-axis 
// int = integer scale for the Y-axis 
$graph->SetScale("textint",0,50); 

// Setup a title for the graph 
$graph->title->Set(''); 

// Setup titles and X-axis labels 
$graph->xaxis->title->Set(''); 
$graph->xaxis->SetTickLabels($xaxis); 
//$graph->xaxis->scale->SetDateFormat('H:i'); 
$graph->xaxis->SetLabelAngle(90); 
$graph->xaxis->SetFont(FF_FONT2); 

// Setup Y-axis title 
$graph->yaxis->title->Set('Channel'); 
$graph->yaxis->scale->SetAutoMax(11); 
$graph->yaxis->title->SetFont(FF_FONT2); 
$graph->yaxis->SetTitlemargin(25); 
// Create the bar plot 

$sp1 = new ScatterPlot($yaxis); 
$sp1->mark->SetType(MARK_FILLEDCIRCLE); 
$sp1->mark->SetFillColor("#61a9f3"); 
$sp1->mark->SetWidth(8); 


// Add the plot to the graph 
$graph->Add($sp1); 

// Display the graph 
$graph->Stroke(); 

?> 
+0

Выглядит хорошо для меня (в том, что вы получаете объекты SimpleXMLElement). Использование 'var_dump' или' print_r' в 'SimpleXMLElement' практически бесполезно, поэтому не полагайтесь на него для фактических целей данных/отладки – Phil

+0

Я сомневаюсь, что это ваша проблема, может возникнуть другая часть кода, вызывающая проблему. –

+0

@mamdouh alramadan, включая полный код. – user2755910

ответ

1

Ваши результаты не пустые, только демпинг SimpleXMLElement не содержит полезных данных.

Доступ и данные с этих объектов, и вы увидите.

Подробнее см. Также комментарии в SimpleXMLElement documentation.

Смежные вопросы