Alright, so I’m trying to create this page where data is displayed from a XML file on the page however, I’m having trouble formatting the text once it is displayed.
I tried using CSS on the PHP file but I only got it to work on Firefox so that’s not going to work:
http://www.newimagemotorsports.com/news.php
PHP CODE:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
$xml_file = "article.xml";
$xml_headline_key = "*NEWS*ARTICLE*ARTICLE_TITLE";
$xml_description_key = "*NEWS*ARTICLE*DESCRIPTION";
$xml_hdate_key = "*NEWS*ARTICLE*HDATE";
$xml_hyperlink_key = "*NEWS*ARTICLE*HYPERLINK";
$story_array = array();
$counter = 0;
class xml_story{
var $headline, $description, $hdate, $hyperlink;
}
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_headline_key, $xml_description_key, $xml_hdate_key, $xml_hyperlink_key, $counter, $story_array;
switch($current_tag){
case $xml_headline_key:
$story_array[$counter] = new xml_story();
$story_array[$counter]->headline = $data;
break;
case $xml_description_key:
$story_array[$counter]->description = $data;
break;
case $xml_hdate_key:
$story_array[$counter]->hdate = $data;
break;
case $xml_hyperlink_key:
$story_array[$counter]->hyperlink = $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);
?>
<html>
<head>
<title>CNT HEADLINE NEWS</title>
<style type="text/css">
h1{
color : #FFFFFF;
font-family: Verdana, Helvetica, sans-serif;
font-size: 10px;
font-weight:bold;
}
date {
color : #FFFFFF;
font-family: Verdana, Helvetica, sans-serif;
font-size: 10px;
font-weight:bold;
}
description {
color : #FFFFFF;
font-family: Verdana, Helvetica, sans-serif;
font-size: 10px;
}
hyperlink {
color : #333;
font-family: Verdana, Helvetica, sans-serif;
font-size: 10px;
}
</style>
</head>
<body bgcolor="#333">
<?php
for($x=0;$x<count($story_array);$x++){
echo " <h1>" . $story_array[$x]->headline . "</h1>
";
echo "
";
echo " <date>" . $story_array[$x]->hdate . "</date>
";
echo " <br/>
";
echo " <description>" . $story_array[$x]->description . "</description>
";
echo " <br/>
";
echo " <hyperlink>" . $story_array[$x]->hyperlink . "</hyperlink>
";
}
?>
</body>
</html>
And even once I get the text formatted properly, I have no idea how I will be able to put this in a table. Any ideas or sites that would point me in the right direction would be greatly appreciated.