Reputation: 5
EDIT: I added my entire code om the bottom of this post My code below worked fine in PHP 5.3 but it is returning empty results in PHP 5.4 What is causing it?
This is the code I am using:
$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];
}
In PHP 5.3, I get the following result (which is what I am expecting):
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
)
)
In PHP 5.4 I get the following:
Array
(
[0] => SimpleXMLElement Object
(
)
)
Array
(
[0] => SimpleXMLElement Object
(
)
[1] => SimpleXMLElement Object
(
)
)
Array
(
[0] => SimpleXMLElement Object
(
)
[1] => SimpleXMLElement Object
(
)
[2] => SimpleXMLElement Object
(
)
)
Here is the original workig code with php 5.3 Version
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();
?>
Upvotes: 0
Views: 243
Reputation: 679
Your results are not empty, only dumping SimpleXMLElement
doesn't show any useful data.
Access and dump data from these objects and you'll see.
For more detail see also comments in SimpleXMLElement documentation.
Upvotes: 1