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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ensure that word exists in variable

    Hello everybody..

    i select website addresses from database all that i need is ensure that is '.com' exists in variable or not

    for example:
    if $x[1]='www.yahoo.com' --> return true.

    but if $x[1]='www.yahoo' --> return false with error message website is not entered correctly.

    thanks in advance

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Use:
    http://www.php.net/strstr

    Search for .com in the string and it will return false if it isn't in the string
    PHP Code:
    if(strstr($x[1], '.com') !== false) {
        
    // Action if .com exists here
    }else{
        
    // Action if .com doesn't exist here

    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)


  •  

    Posting Permissions

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