denoteone Posted April 14, 2009 Share Posted April 14, 2009 if I have a string "PostalCode: 12353" and if I search for PostalCode how can I get the 5 characters after it. Would I use the following code? $text = ' This is your PostalCode: 12353 enjoy!"; $zipcode = strpos($text,"PostalCode:")+6; echo $zipcode; Link to comment https://forums.phpfreaks.com/topic/153950-solved-strpos/ Share on other sites More sharing options...
.josh Posted April 14, 2009 Share Posted April 14, 2009 no. If you want to go that route, you would use the position returned and use substr starting at that position+2 (+1 for the space, +1 more for the starting position of the zip code). Or you could do $text = ' This is your PostalCode: 12353 enjoy!'; preg_match("~PostalCode: (\d{5})~",$text,$code); echo $code[1]; Link to comment https://forums.phpfreaks.com/topic/153950-solved-strpos/#findComment-809117 Share on other sites More sharing options...
denoteone Posted April 14, 2009 Author Share Posted April 14, 2009 Got to love that RegEx. Thanks for your help i am going to use the substring method for now though. Thanks for you help. Link to comment https://forums.phpfreaks.com/topic/153950-solved-strpos/#findComment-809120 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.