#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Nobbies beach, Gold Coast. It's beautiful.
    Posts
    2,575
    Rep Power
    171

    Can't get strpos to work!


    My requirement:

    If string a contains "b" and the other doesn't contain 0.

    But this never shows "APROVE" even when it should.

    PHP Code:
    if (strpos($get_package_res->AL,'b') !== false && strpos$get_package_res->NR'0') === false)
         {
        echo 
    "APROVE";    
         } 
    What am I doing wrong?

    Thanks
    Last edited by zxcvbnm; February 17th, 2013 at 07:38 PM.
  2. #2
  3. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,066
    Rep Power
    1990
    What are the values that it's not working on when you think that it should?

    Basic de-bugging would be to add in a line above the if() statement to see exactly what it's trying to process:
    PHP Code:
    echo "<p>AL: '".$get_package_res->AL."' NR: '".$get_package_res->NR."'</p>"
    Do that and see what the values are when it doesn't do what you expect. You should soon be able to see what's happening with it.
  4. #3
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Nobbies beach, Gold Coast. It's beautiful.
    Posts
    2,575
    Rep Power
    171
    Originally Posted by Catacaustic
    What are the values that it's not working on when you think that it should?

    Basic de-bugging would be to add in a line above the if() statement to see exactly what it's trying to process:
    PHP Code:
    echo "<p>AL: '".$get_package_res->AL."' NR: '".$get_package_res->NR."'</p>"
    Do that and see what the values are when it doesn't do what you expect. You should soon be able to see what's happening with it.
    It prints AL: 'b' NR: '1' . I still cant see it print APROVED. It should, shouldn't it?
  6. #4
  7. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,066
    Rep Power
    1990
    Yes, it should. Unless something else is wrong. I set up this testing code:
    PHP Code:
    $get_package_res = new stdClass ();

    $get_package_res->AL "b";
    $get_package_res->NR 1;

    if (
    strpos ($get_package_res->AL"b") !== false && strpos ($get_package_res->NR"0") === false) {
        echo 
    "APROVE";
    }
    else {
        echo 
    "<p>Not approved</p>";

    That prints APPROVED as you expect it to. It looks like there's something different about the values that you're feeding into it, or there's something strange going on with your system there. I'd almost bet that it's something wrong with the values that you're feeding into it.
  8. #5
  9. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Nobbies beach, Gold Coast. It's beautiful.
    Posts
    2,575
    Rep Power
    171
    You wouldnt believe what the issue was! I had to clear the cache! This is not how I want my browser of php to work. If I make changes to script on the server i want to be able to see the changes!

    I am checking now and I see the same thing is going on with Codeigniter scripts I write. Strangly some changes don't take place unless I clear the cache!
  10. #6
  11. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    Which cache are you talking about? If it's a server cache, that's how they work. If you mean your browser cache, turn it off.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  12. #7
  13. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Nobbies beach, Gold Coast. It's beautiful.
    Posts
    2,575
    Rep Power
    171
    Originally Posted by ManiacDan
    Which cache are you talking about? If it's a server cache, that's how they work. If you mean your browser cache, turn it off.
    Browser cache. I sometimes have strange loggin issues that get solved after clearing browser cache! I use Firefox.
  14. #8
  15. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    Disable the cache in firefox and those problems will go away for you.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo