/    Sign up×
Community /Pin to ProfileBookmark

Read Text File Questions

I have the following sitemap:

[url]http://www.otc.edu/sitemap/sitemap.php[/url]

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?

  • [url]http://www.otc.edu/sitemap/sitemap.html[/url]

    Thanks for any suggestions you can provide. Script is below:

    [code=php]<?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);
    }
    ?>[/code]

    to post a comment
    PHP

    0Be the first to comment 😎

    ×

    Success!

    Help @ryanbutler spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...