SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2006
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    check and output links

    current situation: i have stored a link in a database (ex. www.bob.com)

    what i want to do:
    - call the link
    - make sure it's a proper link
    - output the link

    problem:
    - i dont know how to make sure it's a link. is there a in-built function that can check if a piece of text has 'www' or '.com'?? i hate using reg ex..is there an alternative??
    - when i output the link, it doesn't give me what i want.
    ex.
    PHP Code:
    echo "<a href='$website'>$website</a>"// http://localhost/test/www.bob.com 
    any ideas??

  2. #2
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    London
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Regex was the first thing that came to mind. What about checking if the url exists by "visiting" it:

    PHP Code:
    function is_url($url) {
        
    $fp = @fopen($url,"r");
        if (
    $fp) {
            
    fclose($fp);
            return 
    true;
        } else {
            return 
    false;
        }

    Make sure when you're building the link that the url is complete - including the "http://" part.

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2006
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there a function that lets you search a specific piece of text INSIDE a text string?

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    strpos()

    make sure to see the examples of how to properly use it.

    you could also use these for this purpose
    strstr()
    stristr()


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
  •