...

View Full Version : How to get a word out of a variable



dawg
01-31-2012, 09:19 PM
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

good12

bad114

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.

Fou-Lu
01-31-2012, 09:44 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum