[thelist] PHP to insert press Releases into a detail page

Kasimir K evolt at kasimir-k.fi
Fri Sep 23 11:24:38 CDT 2005

JYoung at sawgrassink.com scribeva in 2005-09-23 13:54:
> I have about 40 press releases that are part of a site redesign. 

> Is it possible to copy the current articles into a text file, and then
> use PHP includes to drop in the appropriate article depending on the
> link that is click by the user? 
> I am looking for the easiest, most efficiently simple solution of course.

About the easiest way to go is to put all the articles in one array and 
use that for both index and detail pages. Put that array in a file of 
its own, say pr_articles.php, and in it:
$articles = array();
$articles[] = array(
    'date' => '2005-09-20',
    'title' => 'First title',
    'body' => 'First pr's text');
$articles[] = array(
    'date' => '2005-09-21',
    'title' => 'Secondtitle',
    'body' => 'Second pr's text');


Then on
> Index page:

require "pr_articles.php";
for ($i = 0; $i < count($articles); $i++){
    echo "<a href='pr_detail.php?article=" . $i . "'>"
       . $articles[$i]['title'] . "</a><br>";

And on
> Detail page:

which is called pr_detail.php

> <div id="press-releases">

$id = $_GET['article'];
echo "<h1>" . $articles[$id]['title'] . "</h1>"
    . "<h2>date: " . $articles[$id]['date'] . "</h2>"
    . $articles[$id]['body'];

> </div>

Not that this example assumes you'll include body's markup in the array, 
like "<p>first paragraph</p><p>second</p>".

If you don't need any markup, you could use 
nl2br($articles[$id]['body']) and simply use two line breaks for paragraphs.

> This seems pretty simple, anyone have
> any suggestions or examples.  Again, I am totally new to PHP.

I hope this is simple enough :-)

For basic info on arrays and strings go:
and check Strings and Arrays.

'Require' and 'for' have links on:

And info on $_GET you'll find at:


More information about the thelist mailing list