IF ($Data ends in '_0') {Something;} ELSE {Something Else;}

Discussion in 'PHP' started by yeahdisk, Mar 14, 2008.

  1. #1
    Hi, I hope someone can help me.

    Currently my PHP script looks like (simplified)

    <?php
    $KW = $_GET['OVRAW'];
    echo 'You Activated Keyword '.$KW.' Just now';
    ?>

    What I want to do is output something different if the $KW string ends in the characters '_0'.

    So, in my own crappy-pseudo-code-style

    <?php
    $KW = $_GET['OVRAW'];

    IF ($KW ends in '_0') {

    echo 'You Activated My Special Keyword '.$KW.' Just now';

    } ELSE {

    echo 'You Activated A Normal Keyword '.$KW.' Just now';

    }
    ?>

    I'm really stuck as I can't find a PHP function that can do this?? Please point me in the right direction someone??

    Cheers

    Chris.
     
    yeahdisk, Mar 14, 2008 IP
  2. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #2
    Maybe explode the the string at the _ and if the $result[ ]=0 {

    echo 'You Activated My Special Keyword '.$KW.' Just now';

    }

    If the _ does not exist the value $result should be null.
     
    Colbyt, Mar 14, 2008 IP
  3. Cobnut

    Cobnut Peon

    Messages:
    184
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Alternatively, you can just use substr...

    if(substr($KW,-2)=="_0") {
    echo "You activated my special keyword $KW just now.";
    }
    else {
    echo "You activated a normal keyword $KW just now.";
    }
    
    PHP:
    Jon
     
    Cobnut, Mar 14, 2008 IP
  4. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #4
    A better suggestion and one that I have not mastered yet. :)
     
    Colbyt, Mar 14, 2008 IP