...

View Full Version : Extracting from array / xml issue



YourDirector
11-16-2011, 09:36 PM
I've built a basic CMS using PHP and xml documents.

This is the code I've used to open a folder containing news articles, It goes through each one identifying specific elements in each then echoing them as desired. The only problem is, its not echoing anything.

I had this working fine using PHP 4 but in the upgrade to 5 somethings gone wrong. Can anyone see what?


<?php
$dh = opendir('./xmlfilms/');

$fileCount = 0;
while ($file = readdir($dh) and $fileCount < 3){
if (preg_match("/^..?$/", $file)) {
continue;
}
$doc = new DOMDocument();
$doc->load("./xmlfilms/" . $file);
$items = $doc->getElementsByTagName("status");
$status = extractText($items);

$items = $doc->getElementsByTagName("headline");
$headline = extractText($items);

$items = $doc->getElementsByTagName("client");
$client = extractText($items);

$items = $doc->getElementsByTagName("featured");
$featured = extractText($items);

$items = $doc->getElementsByTagName("vimeo");
$vimeo = extractText($items);


$items = $doc->getElementsByTagName("keywords");
$keywords = extractText($items);

$items = $doc->getElementsByTagName("uploadFilename_0");
$uploadFilename_0 = extractText($items);


if ($featured != "featured"){
continue;
}
echo "<td align='centre'>";
echo "<span class='featuretitle'>" . $headline . "</class><br><br>";
echo "<a href='http://vimeo.com/" . $vimeo . "' rel='prettyPhoto' title=''><img src='images/filmsimg/" . $uploadFilename_0 . "' style='opacity:0.8;filter:alpha(opacity=80)'
onmouseover='this.style.opacity=1;this.filters.alpha.opacity=100' onmouseout='this.style.opacity=0.8;this.filters.alpha.opacity=80'></a></td><td valign='top'>";
echo "</td>";

$fileCount++;
}
?>

The function "extractText" is:

<?php
function extractText($array){
foreach ($items as $item){
echo $item->nodeValue ."\n";

}
?>

Thanks

kbluhm
11-16-2011, 10:22 PM
is this the function?


function extractText($items){
foreach ($items as $item){
echo $item->nodeValue ."\n";

}

If not, the parameter variable is $array, but you are looping over $items.

Plus, the function is echoing, not returning, so any assignment will be NULL:


$status = extractText($items);

var_dump( $status ); // NULL

Sooo... not sure why the assignments are there.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum