html - Create dynamic sitemap from text file using php -
i have create dynamic site map uni assignment using php. first time studying php please bare me if terminology little wrong!
basically (at suggestion of tutor) have saved names of links in text file called "sitemap.txt". these names names of pages minus extensions , supposed use content generate link. content looks this:
index,services,contact us,register,login,class manager
my code 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 have been able print contents of file page without issues. need convert static text links.
can suggest way? thinking using regex or string matching i'm not sure how.
i not sure asking, if it's creating link out of names, can't ....
$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>"; }
Comments
Post a Comment