SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Adding links

  1. #1
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding links

    Ive managed to figure out a few ways around this script, however, I am falling short on this piece..

    I have a script that writes to a new .txt file and it eventually shows up on a separate page. I am tryingot figure out how to make a link active to the links that someone posts...

    ie::

    <form action="postlinks.php" method="post">
    Author: <input type="text" name="author"><br>
    Adding Linksinput type="text" name="links"><br>
    Link Infobr>
    <textarea name="text" cols="25" rows="10"></textarea><br>

    <input type="submit" value=" Post It! ">
    </form>

    this gets me to my "thank you" type of page. when I follow through on that page- it would bring me to my final destination where everything is shown.

    This is the last part of my script that I need to fix::
    echo "<font color='white'><b>".$date."</b><br>";
    echo '<small>Written by: '.$author.'</small><br>';
    echo '<font size="+1"><i>'.$links.'</i></font><br>';
    echo $text;
    echo '</font><br><br>';
    what I would like to do is get my $links to become an active link. the person would type in a link and it becomes stored in my files for any other user to check out. How do I get it to become active?

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    echo '<font size="+1"><i><a href="'.$links.'">'.$links.'</a></i></font><br>';

  3. #3
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks that seems to work, except for one thing on it...

    it seems to create the link after my domain name::

    for example:

    http://www.mydomain.com/www.newlink.com

    any suggestions to make it its own separate link?

  4. #4
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use strpos with "http://" as the needle to determine if the link is properly typed (protocol included); if !strpos, prepend it to $links.

  5. #5
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im not exactly sure how to go about doing that..
    Would you be able to explain to me how?

  6. #6
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure. Something like this:

    PHP Code:
    $link "www.example.com";
    $needle "http://";
    $check strpos($link$needle);

    if(
    $check === false){
        
    //if "http://" is not present in $link, prepend it yourself
        
    $correctLink "http://" $link;
    }
    else{
        
    //the given link was okay
        
    $correctLink $link;
    }

    print 
    "<a href=\"" $correctLink "\">" $correctLink "</a>"

  7. #7
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much- it works great..

    I really appreciate it.


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
  •