Spinethetic
05-03-2008, 10:38 PM
I've been toying with the idea of a sort-of-cms website that uses a single universal newsarticle.php page that is blank if you solely open that file; but has a php script (where you want the news article to appear) that retrieves a variable from the window.location.href passed on from the previous page
<?php
######################################
# This is where the problem is, somehow retrieving the number "23"
# from the address bar so that it knows which XML file to parse.
# I know that the below function is completely wrong though in regards
# to variable retrieval, but I'am still new to PHP :P
######################################
if (!$myxml=simplexml_load_file('window.location.href')){
echo 'Error reading the XML file';
}
foreach($myxml as $article){
echo '<h3> ' . $article->title . '</h3>';
echo '<a href=','' . $article->sourcelink . '','>' . $article->sourcelink . ' | ' . $article->date . '</a><br />';
echo '' . $article->story . '';
}
?>
ie:
http://mysite.com/index.php has a link that goes to
http://mysite.com/newsarticle.php?id=23
the variable being 23 in which the aforementioned PHP coded into newsarticle.php then parses and displays, say, 23.xml, which could be coded something like this:
<?xml version="1.0" encoding="utf-8" ?>
<index>
<article>
<title>Alien from mars speaks his/her mind at UN conference</title>
<source>BBC World News</source>
<date>12/25/08</date>
<sourcelink>http://bbc.co.uk/world/5674alien.aspx</sourcelink>
<story>blah blah blah blah</story>
</article>
</index>
Likewise if the variable had been http://mysite.com/newsarticle.php?id=24, then 24.xml would have been parsed instead.
Thoughts?
<?php
######################################
# This is where the problem is, somehow retrieving the number "23"
# from the address bar so that it knows which XML file to parse.
# I know that the below function is completely wrong though in regards
# to variable retrieval, but I'am still new to PHP :P
######################################
if (!$myxml=simplexml_load_file('window.location.href')){
echo 'Error reading the XML file';
}
foreach($myxml as $article){
echo '<h3> ' . $article->title . '</h3>';
echo '<a href=','' . $article->sourcelink . '','>' . $article->sourcelink . ' | ' . $article->date . '</a><br />';
echo '' . $article->story . '';
}
?>
ie:
http://mysite.com/index.php has a link that goes to
http://mysite.com/newsarticle.php?id=23
the variable being 23 in which the aforementioned PHP coded into newsarticle.php then parses and displays, say, 23.xml, which could be coded something like this:
<?xml version="1.0" encoding="utf-8" ?>
<index>
<article>
<title>Alien from mars speaks his/her mind at UN conference</title>
<source>BBC World News</source>
<date>12/25/08</date>
<sourcelink>http://bbc.co.uk/world/5674alien.aspx</sourcelink>
<story>blah blah blah blah</story>
</article>
</index>
Likewise if the variable had been http://mysite.com/newsarticle.php?id=24, then 24.xml would have been parsed instead.
Thoughts?