jeffj Posted April 3, 2007 Share Posted April 3, 2007 I need to parse a string and attempt to find a substring in the string that contains 6 numeric digits. the first and last digit may or may not be preceded by a space. I need to find the starting the ending positions of the 6 numeric digits to that I can extract the string and build an href containing the string and replace those 6 digits with a hyperlink. can someone help me... thanks in advance. Jeff Link to comment https://forums.phpfreaks.com/topic/45408-need-help-with-function-to-find-6-digit-numeric-string/ Share on other sites More sharing options...
Leeder Posted April 3, 2007 Share Posted April 3, 2007 You could do a substr for any number and then count 5 characters after that number and put the result in a variable Link to comment https://forums.phpfreaks.com/topic/45408-need-help-with-function-to-find-6-digit-numeric-string/#findComment-220505 Share on other sites More sharing options...
jeffj Posted April 3, 2007 Author Share Posted April 3, 2007 thanks I was looking more for help along the line of a function someone may have already written, since end of string/string length would have to be computer first using your idea to avoid run time errors. Link to comment https://forums.phpfreaks.com/topic/45408-need-help-with-function-to-find-6-digit-numeric-string/#findComment-220515 Share on other sites More sharing options...
grimmier Posted April 3, 2007 Share Posted April 3, 2007 Are the 6 numeric characters the same all the time? if they are always the same characters you can use something like this. if (stristr($string, "6numericCharacters") !== FALSE) { //whatever you wanted to do to the string that contains the 6 numbers } Link to comment https://forums.phpfreaks.com/topic/45408-need-help-with-function-to-find-6-digit-numeric-string/#findComment-220536 Share on other sites More sharing options...
effigy Posted April 3, 2007 Share Posted April 3, 2007 <pre> <?php $string = 'abc123def4567890...'; preg_match('/\d{6}/', $string, $matches, PREG_OFFSET_CAPTURE); print_r($matches); ?> </pre> Link to comment https://forums.phpfreaks.com/topic/45408-need-help-with-function-to-find-6-digit-numeric-string/#findComment-220570 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.