Reputation: 141
I have to create a dynamic site map for a uni assignment using PHP.
I have saved the names of the links in a text file called "sitemap.txt". These names are the names of the pages minus their extensions and I am supposed to use this content to generate a link. The content looks like this:
Index,Services,Contact Us,Register,Login,Class Manager
My code is below:
<?php
$fp = fopen("sitemap.txt", "r");
echo '<p class="smallerText">';
while(!feof($fp))
{
$line = fgets($fp);
$array = explode(",", $line);
}
fclose($fp);
$num_elements = count($array);
$list = '<ul class="servicesList" name="sitemap">';
for($count = 0; $count < $num_elements; $count++)
{
$list .= "<li>$array[$count]</li>";
}
$list .= "</ul>";
echo "$list";
?>
So basically I have been able to print the contents of the file to the page without any issues. But I need to convert the static text into links.
Can anyone suggest a way? I was thinking using regex or string matching but I'm not sure how.
Upvotes: 0
Views: 427
Reputation: 3453
I am not sure what you are asking, but if it's creating link out of those names, can't you just ....
$YourDomain="http://mydomain.com/";
$ext=".php";
for($count = 0; $count < $num_elements; $count++)
{
$list .= "<li><a href=\"$YourDomain.$array[$count].$ext\">$array[$count]</a></li>";
}
Upvotes: 1