2011-11-28 59 views
0

我有一个奇怪的问题正在进行。它可能与服务器有关,但我不知道要寻找什么。.shtml和.php页面包含虚拟和运行PHP问题

我有一个PHP页面有几个虚拟包括:

<?php virtual ("nav.shtml"); ?> 

...整个它。我也有一个解析器以表格形式显示XML数据。

分析器的工作原理与标准:

<?php include ('parser.php'); ?> 

...但是,如果我有以上的包括虚拟,解析器不起作用。或者至少它不会“查找文件”,然而,该文件是存在的,它的工作原理之上的虚拟,显示它罚款...

例如,这个工程:

<?php include ('parser.php'); ?> 
<?php virtual ('file.shtml'); ?> 

这没有按” t:

<?php virtual ('file.shtml'); ?> 
<?php include ('parser.php'); ?> 

我在这里错过了什么吗?

这里是index.shtml页面代码:

<?php virtual ("nav.shtml"); ?> 
    <div id="sortabletable"> 
         <table id="myTable" class="tablesorter"> 
         <thead> 
          <tr> 
          <th>Subject</th> 
          <th>Committee</th> 
          <th>Witness</th> 
          <th>Date</th> 
          <th>Bill</th> 
          <th>Link</th> 
          </tr> 
         </thead> 
         <tbody> 
          <?php include('parser.php'); ?> 
         </tbody> 
         </table> 
        </div> 
    <?php virtual ("footer.shtml"); ?> 

这里是解析器代码:

<?php 
$xml_file = "test.xml"; 

$xml_subject_key = "*TESTIMONIES*CONGRESS*SUBJECT"; 
$xml_committee_key = "*TESTIMONIES*CONGRESS*COMMITTEE"; 
$xml_witness_key = "*TESTIMONIES*CONGRESS*WITNESS"; 
$xml_date_key = "*TESTIMONIES*CONGRESS*DATE"; 
$xml_bill_key = "*TESTIMONIES*CONGRESS*BILL"; 
$xml_link_key = "*TESTIMONIES*CONGRESS*LINK"; 

$congress_array = array(); 

$counter = 0; 
class xml_story{ 
    var $subject, $committee, $witness, $date, $bill, $link; 
} 

function startTag($parser, $data){ 
    global $current_tag; 
    $current_tag .= "*$data"; 
} 

function endTag($parser, $data){ 
    global $current_tag; 
    $tag_key = strrpos($current_tag, '*'); 
    $current_tag = substr($current_tag, 0, $tag_key); 
} 

function contents($parser, $data){ 
    global $current_tag, $xml_subject_key, $xml_committee_key, $xml_witness_key, $xml_date_key, $xml_bill_key, $xml_link_key, $counter, $congress_array; 
    switch($current_tag){ 
     case $xml_subject_key: 
      $congress_array[$counter]->subject = $data; 
      break; 
     case $xml_committee_key: 
      $congress_array[$counter]->committee = $data; 
      break; 
     case $xml_witness_key: 
      $congress_array[$counter]->witness = $data; 
      break; 
     case $xml_date_key: 
      $congress_array[$counter]->date = $data; 
      break; 
     case $xml_bill_key: 
      $congress_array[$counter]->bill = $data; 
      break; 
     case $xml_link_key: 
      $congress_array[$counter]->link = $data; 
      $counter++; 
      break; 
    } 
} 

$xml_parser = xml_parser_create(); 

xml_set_element_handler($xml_parser, "startTag", "endTag"); 

xml_set_character_data_handler($xml_parser, "contents"); 

$fp = fopen($xml_file, "r") or die("Could not open file"); 

$data = fread($fp, filesize($xml_file)) or die("Could not read file"); 

if(!(xml_parse($xml_parser, $data, feof($fp)))){ 
    die("Error on line " . xml_get_current_line_number($xml_parser)); 
} 

xml_parser_free($xml_parser); 

fclose($fp); 

// A simple for loop that outputs our final data. 
//echo sizeof($congress_array); 
for($x=0; $x<count($congress_array); $x++){ 
    echo "<tr><td scope='row'>" . $congress_array[$x]->subject . "</td>"; 
    echo "<td>" . $congress_array[$x]->committee . "</td>"; 
    echo "<td>" . $congress_array[$x]->witness . "</td>"; 
    echo "<td>" . $congress_array[$x]->date . "</td>"; 
    echo "<td>" . $congress_array[$x]->bill . "</td>"; 
    echo '<td><a href="'. $congress_array[$x]->link .'"><img src="download-icon.png" width="20" height="20" alt="' . $congress_array[$x]->subject . '"/></a></td></tr>'; 
} 
?> 

回答

0

如果您在某些情况下使用虚拟和包含,您需要拆分包含代码并将其运行在.shtml文件的顶部。然后让输出包括你需要输出的地方。为我的问题工作。

谢谢!

0

“将无法找到文件” ......哪些文件? XML? shtml?

没有看到你的代码(咳嗽)我只能猜测你的.shtml包括一些可执行PHP是不安的事情......

但没有公布所有代码,我们可以是猜测

+0

对不起,找不到XML。 SHTML文件中没有PHP。添加了代码... – jasonflaherty