Objective: To create a simple way to share links to relevant articles with co-workers that is easily updated and allows for grouping of articles by topic.
Solution: A PHP based system using a plain text file to store links and topic data.
Technologies Used: PHP, HTML
articlelist.txt
A simple tab-delimited text file used for storing link information
#FORMAT: URL(tab)Title(tab)Category
http://site1/ Site Description 1 Category1
http://site2/ Site Description 2 Category2
http://site3/ Site Description 3 Category2
http://site4/ Site Description 4 Category1
index.php
PHP file that parses the list of article links and writes them to the page. If a specific category has been chosen it will only display those article links.
<html>
<head>
<?php
$str_title="Links";
if(isset($_GET['tag'])){
$tag=$_GET['tag'];
}else{
$tag=false;
}
if($tag){
$str_title="Links for {$tag}";
}
?>
<title><?=$str_title ?></title>
</head>
<body>
<?php
$arr_list=file('articlelist.txt');
$int_listcount=count($arr_list);
if($tag){
print "<h1>{$tag} Links</h1>\n";
print "<ul>\n";
for($i=1;$i<$int_listcount;$i++){
$arr_parts=explode("\t",$arr_list[]);
if($tag==trim($arr_parts[2])){
print "\t<li>";
print '<a href="'.$arr_parts[0].'">';
print $arr_parts[1].'</a>';
print ' (<a href="./?tag='.trim($arr_parts[2])
print '">'.trim($arr_parts[2]).'</a>)';
print "</li>\n";
}
}
print "</ul>\n";
print '<a href="./">Back to Normal View</a>'."\n";
}else{
print "<h1>Article Links</h1>\n";
print "<ul>\n";
for($i=1;$i<$int_listcount;$i++){
$arr_parts=explode("\t",$arr_list[$i]);
print "\t<li>";
print '<a href="'.$arr_parts[0].'">';
print $arr_parts[1].'</a>';
print ' (<a href="./?tag='.trim($arr_parts[2])
print '">'.trim($arr_parts[2]).'</a>)';
print "</li>\n";
}
print "</ul>\n";
}
?>
</body>
</html>