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. Link to comment https://forums.phpfreaks.com/topic/245948-string-help/ 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; Link to comment https://forums.phpfreaks.com/topic/245948-string-help/#findComment-1263126 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); Link to comment https://forums.phpfreaks.com/topic/245948-string-help/#findComment-1263129 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.