KC22 Posted January 25, 2008 Share Posted January 25, 2008 I am looking to find how to find a substring within a string. I need to pull the string that comes b4 the colon in a value like the following: 62:2766f0dd07c471436859ff510c38a618 There is not a specified # of characters that come b4 the colon. Can anyone help?!?! Thanx in advance Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted January 25, 2008 Share Posted January 25, 2008 I'd use explode: <?php $str = '62:2766f0dd07c471436859ff510c38a618'; list($before,$after) = explode(':',$str); echo $before; ?> Quote Link to comment Share on other sites More sharing options...
toplay Posted January 25, 2008 Share Posted January 25, 2008 Something like this: if (preg_match('/^([^:]*?):/', $string, $matches)) { $result = $matches[1]; } else { $result = ""; } Quote Link to comment Share on other sites More sharing options...
KC22 Posted January 25, 2008 Author Share Posted January 25, 2008 Both of these worked perfectly! Thanks to both! 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.