Web Analytics Made Easy -
StatCounter include links only - CodingForum

Announcement

Collapse
No announcement yet.

include links only

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • include links only

    I'd like to allow my site map to be automatically updated when links are added to subpages. Is there a way to only include the links from other files, and none of the other stuff?
    designsbychris.com

  • #2
    There are two ways to do this I suppose.

    One would be to include your links in a database, and so when you add new links, you add them to your database, and they will show up in your site map, as well as your sub-pages.

    The other way would be to have your site map code to parse all the other pages for <a href=... tags and grab the links, and display them on the site map.

    Which is easier? Probably the database solution, however, you'll have to rewrite some of your code in your other pages. However, if you've got a lot of links and a lot of different pages, then it might be easier to write the parsing routine instead of adding all the links to the database.

    Hope that helps,
    Sadiq.

    Comment


    • #3
      I'm trying to figure out the 2nd option you mentioned: parsing the files for the links. I can't quite find the right function on php.net though, can you point me in the right direction?
      designsbychris.com

      Comment


      • #4
        file_get_contents() and preg_match_all() would work. Crude, but effective. =)

        Comment


        • #5
          Here's what I have, and it works, but I still have issues.

          PHP Code:
          <?php
          ob_start
          ();
          include(
          "txt/belief_main.txt");
          $belieflinks ob_get_contents();
          $belieflinks str_replace('\"'""$belieflinks);
          $belieflinks str_replace('reglink'"sitemaplink"$belieflinks);
          ob_end_clean();

          echo 
          "<a href=believe.html?page=main class=red>
                Some of the Things That I Believe</a><br> &nbsp; "
          ;
          preg_match_all("|<a[^>]+>(.*)</[^>]+>|U"$belieflinks
             
          $outPREG_PATTERN_ORDER);
          echo 
          $out[0][0] . "<br> &nbsp; " $out[0][1] . "<br> &nbsp; ";
          echo 
          $out[0][2] . "<br> &nbsp; " $out[0][3] . "<br> &nbsp; ";
          echo 
          $out[0][4] . "<br> &nbsp; " $out[0][5] . "<br> &nbsp; ";
          echo 
          $out[0][6] . "<br> &nbsp; " $out[0][7] . "<br> &nbsp; ";
          echo 
          $out[0][8] . "<br> &nbsp; " $out[0][9] . "<br><br>";
          ?>
          Issue #1 - Do I have to repeat this code for every file I want to strip for links, or is there some kind of loop that I can set up?
          Issue #2 - When a file has less than 10 links, there is an unneccessary amount of blank space below the links (due to the <br> tags), is there some way that I can say if_exists ($out[0][8]){echo $out[0][8]}?
          Issue #3 - When a file has more than 10 links, is there a way to (in addition to the previous issue) set up a variable that increments the # of the link that the code seeks to include?
          Last edited by BroChris; Feb 19, 2004, 07:29 AM.
          designsbychris.com

          Comment


          • #6
            Disregard issues 2 and 3. A simple while function solved it:
            PHP Code:
            $i=0;
            while (isset(
            $out[0][$i]))
             {
              echo 
            $out[0][$i] . "<br> &nbsp; ";
              
            $i++;
             } 
            Concerning issue 1, I just wrote it all out, so nevermind. Thanks for all your help.
            Last edited by BroChris; Feb 19, 2004, 02:44 PM.
            designsbychris.com

            Comment

            Working...
            X