Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post

    Check for http:// in a string

    I'm trying to figure out how to check a users input for http:// and if its not there insert the http:// Ideas?
    Just a simple Developer and IT student
    My Blog
    My Portfolio
    My Playground of Technology

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    If you expect it at the beginning of the string you can do something like this:
    PHP Code:
    $string 'http://www.google.com';
    $string = (substr(ltrim($string), 07) != 'http://' 'http://' '') . $string

  • #3
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post
    so if the user enters www.blah.com it will end up http://www.blah.com?
    Just a simple Developer and IT student
    My Blog
    My Portfolio
    My Playground of Technology

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    To understand Inigoesdr's code you'll want to study these web pages:

    substr()

    ltrim()

    Ternary operators (scroll down til you get to the paragraph on ternary operators)

    I don't think you should use any code that you don't understand.

  • #5
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post
    what you do you think is the best way to store links in a database I tried htmlentinty(), special chars. this is how my form processor is handling it

    PHP Code:
    $blog1_url mysql_real_escape_string(htmlentities($_POST['blog1_url'])); 
    Just a simple Developer and IT student
    My Blog
    My Portfolio
    My Playground of Technology


  •  

    Posting Permissions

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