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 Link to comment https://forums.phpfreaks.com/topic/87766-solved-string-manipulation/ 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; ?> Link to comment https://forums.phpfreaks.com/topic/87766-solved-string-manipulation/#findComment-448943 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 = ""; } Link to comment https://forums.phpfreaks.com/topic/87766-solved-string-manipulation/#findComment-448949 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! Link to comment https://forums.phpfreaks.com/topic/87766-solved-string-manipulation/#findComment-448993 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.