Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2011
    Thanked 0 Times in 0 Posts

    How to get a word out of a variable

    I have a code that if the item is in the database it does a update, but if not it does a insert

    I was going to do it like



    so if it is in it would be good, else it would be bad, how do I check if the word good or bad is in there?

    I figure I will use a str_replace to remove good or bad.

    Thanks for any help.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,662 Times in 2,631 Posts
    So end up with 12 and 114? Str_replace seems to be the best option to me if you know it will be 'good' and 'bad' as a part of the string. Substr with a strpos can also be used, but to me seems a little overboard in comparison (1 line versus 4 lines).
    You can't pull them out of the variable name $good112 though, only the value of a variable - variables cannot start with numbers, so just in case that's what you want then no, you would want to use arrays instead.


    Posting Permissions

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