pengu Posted August 29, 2011 Share Posted August 29, 2011 Hi, I'm trying to figure out how to get some numbers out of a string. Example of strings $string1 = "3-tech"; $string2 = "109-bobby"; $string3 = "4-Charlie1994"; $string4 = "55-Mr-Smith"; What I want to do is grab everything BEFORE the "-" and the first dash. I'm having a brain meltdown atm and just can't figure it out, I know it's something simple. Quote Link to comment Share on other sites More sharing options...
gizmola Posted August 29, 2011 Share Posted August 29, 2011 Believe it or not, you can cast all those values to int and you'll get the starting number: $string1 = "3-tech"; echo (int)$string1; Quote Link to comment Share on other sites More sharing options...
silkfire Posted August 29, 2011 Share Posted August 29, 2011 There are many ways you can do this. Another way is: $string1 = '3-tech'; $string1 = strstr($string1, '-', true); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.