ryanbutler Posted June 7, 2007 Share Posted June 7, 2007 I have the following sitemap: http://www.otc.edu/sitemap/sitemap.php I'm reading in a text file from this page. I have a few things in PHP which I'm not sure how it would be done. 1. Is there a way using a regex that I could check for directories and only display the top level URL for each directory? For example, the "about" directory has many pages inside, when all I need to display is the home page, index.php. I have more pages being crawled and sent to Google that I don't want showing up. 2. Is there a sort command that would organize the listing of each directory? Right now, it's not in the correct order. 3. Would there be a way to display the directory and then the filename, such on this page? http://www.otc.edu/sitemap/sitemap.html Thanks for any suggestions you can provide. Script is below: <?php $theFile=fopen("urllist.txt", "r"); //error check to ensure we can open the text file and get results back, if not, display a //warning. if(!$theFile){ echo "Couldn't open the data file. Try again later."; } else{ //read the contents of the text file while(!feof($theFile)) { $data=explode("\n", fgets($theFile)); print "<tr>\n"; for($i=0;$i<=count($theFile);$i++){ print "<td>$data[$i]</td>"; } print "</tr>\n"; } //done with the file, call the fclose function, passing variable fclose($theFile); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/54651-reading-text-files-questions/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.