aximbigfan Posted October 6, 2008 Share Posted October 6, 2008 Sorry if this is not the right forum, dunno if this fit under RegExp or not. Basically, I need a function to see if the beginnign of a string matches another string. Let's say $match = '/1/2/3/'; and the haystack is '1/2/3/4/5'. In this case, the function would return true, but in this case haystack: '2/3/1/2/3' the function would return false. Thanks, Chris Link to comment https://forums.phpfreaks.com/topic/127186-find-a-string-at-the-beginning-of-a-string/ Share on other sites More sharing options...
Bendude14 Posted October 6, 2008 Share Posted October 6, 2008 have a read here http://au.php.net/preg_match Link to comment https://forums.phpfreaks.com/topic/127186-find-a-string-at-the-beginning-of-a-string/#findComment-657908 Share on other sites More sharing options...
ibechane Posted October 6, 2008 Share Posted October 6, 2008 Don't use preg_match; it's overkill Use strpos instead. It returns the position of a string within a string. Just test to make sure it's equal to 0. http://us2.php.net/manual/en/function.strpos.php EDIT first position is 0, not 1 Link to comment https://forums.phpfreaks.com/topic/127186-find-a-string-at-the-beginning-of-a-string/#findComment-657911 Share on other sites More sharing options...
aximbigfan Posted October 6, 2008 Author Share Posted October 6, 2008 Perfect, thanks! Chris Link to comment https://forums.phpfreaks.com/topic/127186-find-a-string-at-the-beginning-of-a-string/#findComment-657919 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.