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 7 of 7

Thread: help with if()

  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts

    help with if()

    I did this once before but now I can't remember what it was I did to make it work.

    I need do this

    Code:
    if($something islike $something){$show = 'that'};
    What would I put where I have 'islike'?

    Thanks

  • #2
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok you are close to it

    PHP Code:
    if($something == $something){$show 'that';} 
    or
    PHP Code:
    if($something == $something){$show 'that';}else{$show 'this';} 
    also as
    PHP Code:
    if($something == $something){
        
    $show 'that';
    }elseif(
    $something == $something){
        
    $show 'other';
    }else{
        
    $show 'this';

    Last edited by damon.whitt; 05-04-2009 at 04:57 PM.

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by damon.whitt View Post
    ok you are close to it

    PHP Code:
    if($something == $something){$show 'that';} 
    or
    PHP Code:
    if($something == $something){$show 'that';}else{$show 'this';} 
    That doesn't really work when I was doing it that way.

    I'm trying to get the end users device they are on. So I start with this.

    Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_2_1 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Mobile/5H11

    I try to build it a few versions ahead so I can't just do like

    Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_2_2 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Mobile/5H11

    or

    Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0_0 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Mobile/5H11

    Because the webkit version changes and I don't know what that will be. So I was trying to do it like.

    if($device == 'iPhone 2_2_1'){$device_short = 'iPhone 2_2_1'}

    Then I would build a few versions ahead so I don't have to update it the second a new firmware comes out.

    But for some reason when I do == I end up getting the full device name or nothing at all not the shortened one. So thats why I figured it was something different for "is like" not $this == $this
    Last edited by dlewis23; 05-04-2009 at 05:00 PM.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    You may use strstr()
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    You might want to do that with regular expressions.

    PHP Code:
    if (preg_match("/iPhone/"$device)) {$device_short "iPhone";} 

  • Users who have thanked venegal for this post:

    dlewis23 (05-04-2009)

  • #6
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you have to tell the $device_short what it is to be in value or use a str_replace
    PHP Code:
    $device_short str_replace(" """$device); // this will remove all spaces 
    is this what you are looking for?

  • #7
    New Coder
    Join Date
    Jul 2008
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by venegal View Post
    You might want to do that with regular expressions.

    PHP Code:
    if (preg_match("/iPhone/"$device)) {$device_short "iPhone";} 

    Thank you, That worked just the way I wanted.


  •  

    Posting Permissions

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