If string/text exist in php file

Discussion in 'PHP' started by thesurface, Mar 23, 2010.

  1. #1
    Hello i have in my php file this
    $name = 'blablabla';
    PHP:
    - and how can i check if the string $name exists also how can i check if $name isnt empty or if have the word included the letter a? :)

    thanks
     
    thesurface, Mar 23, 2010 IP
  2. Nyu

    Nyu Peon

    Messages:
    79
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    To check if the variable $name is set and not empty you can use the isset and empty construct. To check if the string contains an "a" you can use the function strpos which will return the position a specified string was found or false if it was not found ;)

    You can take a look how these constructs and function work at php.net
     
    Nyu, Mar 23, 2010 IP
  3. Rory M

    Rory M Peon

    Messages:
    1,020
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    if(isset($name)==false)
    {
    //Value Is Not Set
    }
    elseif($name == "")
    {
    //Value is an empty string
    }
    
    PHP:
     
    Rory M, Mar 23, 2010 IP
  4. thesurface

    thesurface Active Member

    Messages:
    260
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #4
    thanks guys you are veeeery helpful :)
     
    thesurface, Mar 23, 2010 IP