Results 1 to 3 of 3

Thread: php5 : Testing for null string

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Godzone, oops Oz
    Posts
    355

    Question php5 : Testing for null string

    What is the php equiv of the following test for a null string value

    Code:
    $value = somefuntion($A, $B)
    
    if not($value) then
       * string is empty do processing
    else
       * string has a value rock on dude
    end
    TIA and go Fiji this evening ....

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: php5 : Testing for null string

    are you testing for a null value, or an empty string?

    PHP Code:
    if(empty($value)){
      
    // this value is an empty string -- ""
    }else{
      
    // this value is not an empty string

    PHP Code:
    if(is_null($value)){
      
    // this value == null
    }else{
      
    // this value != null

    PHP Code:
    if($value === ""){
      
    // $value is exactly equal to an empty string ("")
    }else{
      
    // $value is not an empty string

    PHP Code:
    if($value === null){
      
    // $value is exactly equal to null
    }else{
      
    // $value is not null

    you should be alright using empty() to test for an empty string and is_null() to test for a null value.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Godzone, oops Oz
    Posts
    355

    Re: php5 : Testing for null string

    Think empty() looks like what I'm after. Will test him out this morning and see how I go

Posting Permissions

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



Click Here to Expand Forum to Full Width