SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)

    Experimentations in PHP

    It is funny that some of the coolest things are created out of necessity.

    I recently wanted to create a truly dynamic linking system for a site but I did not want to have it call a database or anything like that. So I put the link name and the link into an array (that is held in an include file) and then wrote a function that output the array on the site in the preformatted way.

    Well I decided to go a step further and make the function look at the current page that it was on and not display its link but instead a link to the homepage below all of the regular links. I just did an eregi(); of the URL and then replaced the found text with the home link.

    I can post the code if anyone is interested.

    I would like to hear any other "cool things brought out of necessity" stories....

  2. #2
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not quite sure what you're talking about, but I'd love to see the code.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    United Kingdom
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd like to take a look at the code too. Is it like a database of links?
    No one is a virgin, life screws us all

  4. #4
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Sabre, that is basically what it is except that it doesn't use a DB

    Here is the code.

    The include file that holds the links and the link titles:
    PHP Code:
    <?
    $links 
    = array ( "News" => "news.php",
                     
    "About Me" => "about.php",
                     
    "Resume" => "resume.php",
                     
    "Scripts" => "scripts.php",
                     
    "Programs" => "programs.php",
                     
    "Links" => "links.php",
             
    "Friends" => "friends.php",
                     
    "Pictures" => "pictures.php");
    ?>
    And the function that does the processing:
    PHP Code:
    <?
    while (list ($key$val) = each ($links))
    {
        if(
    eregi($val$PHP_SELF))
        {
        
    $home "index.php";
        continue;
        }    
    ?>
     
    <A HREF="<? echo $val?>" class="links">:: <? echo $key?> ::</A><BR>

    <?
    }
    if(
    $home)
    ?>

    <P>
    <A HREF="<? echo $home?>" class="links">:: <? echo "Home"?> ::</A>
    <BR>

    <? ?>
    It is down and dirty and can be refined quite a bit.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If i were you, i'd just say something like:

    $name = Your input using post or get.
    $link = $name.php

    This way you don't need to fill in all the arrays in your script.

    works fine for me (I made it in CGI), http://www.dijksma.net/readarticle.cgi?1 opens 1.txt, it's simple as that!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •