我有一个小的新闻小部件,它在PHP 5.2中工作,但在PHP 5.3中不起作用。当您单击showArticle.php的链接时,URL会反映正确的XML文件名,但它不会传递showArticle.php文件中的第一个if语句。 这是新闻小部件的代码:
<?php
if (PHP_VERSION>='5')
require_once('domxml-php4-to-php5.php');
function extractText($array){
if(count($array) <= 1){
//we only have one tag to process!
for ($i = 0; $i<count($array); $i++){
$node = $array[$i];
$value = $node->get_content();
}
return $value;
}
}
?>
<?php
$dh = opendir('./xml/');
$fileCount = 0;
while ($file = readdir($dh) and $fileCount < 3){
if (eregi("^..?$", $file)) {
continue;
}
$open = "./xml/".$file;
$xml = domxml_open_file($open);
//we need to pull out all the things from this file that we will need
to
//build our links
$root = $xml->root();
$stat_array = $root->get_elements_by_tagname("status");
$status = extractText($stat_array);
$ab_array = $root->get_elements_by_tagname("abstract");
$abstract = extractText($ab_array);
$h_array = $root->get_elements_by_tagname("headline");
$headline = extractText($h_array);
$img_array = $root->get_elements_by_tagname("image");
$image = extractText($img_array);
$lead_array = $root->get_elements_by_tagname("para-intro");
$para["intro"] = extractText($lead_array);
if ($status != "live"){
continue;
}
echo "<div class=\"col-md-12 newsbox\"><img style=\"margin-bottom: 10px;\" width=\"100%\" src=\"images/news/".$image."\"><div class=\"newsboxtext\"><a href=\"http://paneilldesign.com/NDPsite/showArticle.php?file=".$file. "\"><h2 class=\"mainheadline2\"> ".$headline . "</h2></a><a href=\"showArticle.php?file=".$file . "\"><button style=\"margin-top:5px;\" type=\"button\" class=\"btn btn-sm btn-default\">+ Read More</button></a></div><hr class=\"linedivider\">
</div>";
$fileCount++;
}
?>
这是showArticle.php的代码
<?php session_start(); ?>
<?php
if (PHP_VERSION>='5')
require_once('domxml-php4-to-php5.php');
function extractText($array){
if(count($array) <= 1){
//we only have one tag to process!
for ($i = 0; $i<count($array); $i++){
$node = $array[$i];
$value = $node->get_content();
}
return $value;
}
}
//pull in the XML file
if ($file == ""){
echo "<h2>You didn't choose a file to edit!</h2>";
echo "<a href=\"ndpnews.php\">Go back to index and choose a file</a>";
} else {
$open = "./xml/" . $file;
$xml = domxml_open_file($open);
$root = $xml->root();
$id = $root->get_attribute("id");
$h_array = $root->get_elements_by_tagname("headline");
$headline = extractText($h_array);
$stat_array = $root->get_elements_by_tagname("status");
$status = extractText($stat_array);
$a_array = $root->get_elements_by_tagname("author");
$author = extractText($a_array);
$e_array = $root->get_elements_by_tagname("email");
$email = extractText($e_array);
$ab_array = $root->get_elements_by_tagname("abstract");
$abstract = extractText($ab_array);
$kl_array = $root->get_elements_by_tagname("keywords");
$keywords = extractText($kl_array);
$img_array = $root->get_elements_by_tagname("image");
$image = extractText($img_array);
$lead_array = $root->get_elements_by_tagname("para-intro");
$para["intro"] = extractText($lead_array);
$second_array = $root->get_elements_by_tagname("para-main");
$para["main"] = extractText($second_array);
$con_array = $root->get_elements_by_tagname("para-conclusion");
$para["con"] = extractText($con_array);
$logo_array = $root->get_elements_by_tagname("logo");
$logo = extractText($logo_array);
$dt_array = $root->get_elements_by_tagname("dateandtime");
$dateandtime = extractText($dt_array);
$wh_array = $root->get_elements_by_tagname("where");
$where = extractText($wh_array);
$ph_array = $root->get_elements_by_tagname("phone");
$phone = extractText($ph_array);
$web_array = $root->get_elements_by_tagname("website");
$website = extractText($web_array);
$map_array = $root->get_elements_by_tagname("map");
$map = extractText($map_array);
$pagetitle_array = $root->get_elements_by_tagname("pagetitle");
$pagetitle = extractText($pagetitle_array);
?>