unrelenting Posted March 22, 2009 Share Posted March 22, 2009 I have variables that all start with a number followed by a period and then a space and a team name. I need to grab just the number at the beginning but can't figure out the method to do it with all the available functions. For instance: 1. UConn 5. Purdue 12. Cleveland St. I need it to be able to handle single digit numbers as well as double digits. I know this is simple to some of you guys that know php well but I have spent almost an hour at this junction and am forced to ask. Quote Link to comment https://forums.phpfreaks.com/topic/150611-solved-need-help-with-trim-or-some-equivilent/ Share on other sites More sharing options...
Maq Posted March 22, 2009 Share Posted March 22, 2009 If the string are always going to begin with the rank then team name you can use: $s = "12. Cleveland St."; preg_match("/^[0-9]+/", $s, $match); echo $match[0]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/150611-solved-need-help-with-trim-or-some-equivilent/#findComment-791129 Share on other sites More sharing options...
unrelenting Posted March 23, 2009 Author Share Posted March 23, 2009 If the string are always going to begin with the rank then team name you can use: <?php $s = "12. Cleveland St."; preg_match("/^[0-9]+/", $s, $match); echo $match[0]; ?> Thanks, That worked perfectly. Quote Link to comment https://forums.phpfreaks.com/topic/150611-solved-need-help-with-trim-or-some-equivilent/#findComment-791463 Share on other sites More sharing options...
Maq Posted March 23, 2009 Share Posted March 23, 2009 Sure. Regex is your best bet hear cause if you tried to explode on ". " (dot space) there could be a team with that in their name. Please mark as [sOLVED] too, thx. Quote Link to comment https://forums.phpfreaks.com/topic/150611-solved-need-help-with-trim-or-some-equivilent/#findComment-791471 Share on other sites More sharing options...
unrelenting Posted March 23, 2009 Author Share Posted March 23, 2009 Sure. Regex is your best bet hear cause if you tried to explode on ". " (dot space) there could be a team with that in their name. Please mark as [sOLVED] too, thanks. You mean like 1. N. Carolina? You think further ahead than I. Topic Solved. Quote Link to comment https://forums.phpfreaks.com/topic/150611-solved-need-help-with-trim-or-some-equivilent/#findComment-791490 Share on other sites More sharing options...
Maq Posted March 23, 2009 Share Posted March 23, 2009 You mean like 1. N. Carolina? Exactly. Quote Link to comment https://forums.phpfreaks.com/topic/150611-solved-need-help-with-trim-or-some-equivilent/#findComment-791491 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.