I have a strange issue going on. It may be server related, but I don’t know what to look for.
I have a .php page with a few Virtual Includes:
<?php virtual ("nav.shtml"); ?>
…throughout it. I have also a parser that is displaying XML data in a table form.
The parser works with the standard:
<?php include ('parser.php'); ?>
…however, if I have the Virtual above the include, the parser doesn’t work. Or at least it will not “find the file” however, the file is there and it works ABOVE the virtual, displaying it fine…
For example, this works:
<?php include ('parser.php'); ?>
<?php virtual ('file.shtml'); ?>
This doesn’t:
<?php virtual ('file.shtml'); ?>
<?php include ('parser.php'); ?>
Am I missing something here?
Here is the index.shtml page code:
<?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"); ?>
Here is the parser code:
<?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>';
}
?>
If you use Virtual and Includes in some cases you will need to split your includes code and run it at the top of your .shtml file. Then have the output includes where you need the output. Worked for my issue.
Thanks!