2011-11-28 109 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