ahs10 Posted February 13, 2008 Share Posted February 13, 2008 i have a text string in which i would like to assign all the numbers after a particular string to a variable, stopping when it gets to a space. i'm having trouble with the pattern syntax. if the string i was searching for was "&RECORD_ID=123456789 ", what would i use? i want all the numbers contained between the equal sign and space. also, i can't find a good quick reference guide for this pattern syntax. php.net does a great job of explaining the preg_match function, but i'm having trouble grasping the pattern syntax explanations. any help is much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/90975-pattern-syntax-with-preg-match/ Share on other sites More sharing options...
PHP Monkeh Posted February 13, 2008 Share Posted February 13, 2008 This wouldn't happen to be in a URL would it? Just seeing the ampersand there makes it seem likely Quote Link to comment https://forums.phpfreaks.com/topic/90975-pattern-syntax-with-preg-match/#findComment-466258 Share on other sites More sharing options...
ahs10 Posted February 13, 2008 Author Share Posted February 13, 2008 yes it is, a get variable of a url Quote Link to comment https://forums.phpfreaks.com/topic/90975-pattern-syntax-with-preg-match/#findComment-466269 Share on other sites More sharing options...
sasa Posted February 13, 2008 Share Posted February 13, 2008 try <?php $a = '&RECORD_ID=123456789&bla'; preg_match('/RECORD_ID=([0-9]+)/i',$a, $b); echo $b[1]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/90975-pattern-syntax-with-preg-match/#findComment-466275 Share on other sites More sharing options...
PHP Monkeh Posted February 13, 2008 Share Posted February 13, 2008 If that's in the URL you could just use $_GET['RECORD_ID'] though? Doesn't seem any need for the regexp. Quote Link to comment https://forums.phpfreaks.com/topic/90975-pattern-syntax-with-preg-match/#findComment-466289 Share on other sites More sharing options...
ahs10 Posted February 13, 2008 Author Share Posted February 13, 2008 i could, if i had control over the server the url was hosted on. i'm parsing a remote page which contains that url. the string i'm searching is the source code of the page. if you have the time, can you explain the syntax of the pattern? what does '/RECORD_ID=([0-9]+)/i' do? Quote Link to comment https://forums.phpfreaks.com/topic/90975-pattern-syntax-with-preg-match/#findComment-466312 Share on other sites More sharing options...
sasa Posted February 13, 2008 Share Posted February 13, 2008 / - start and end RECORD_ID= - pattern looking for () - subpart [0-9] - any digit + - one or more times try to print_r($b); Quote Link to comment https://forums.phpfreaks.com/topic/90975-pattern-syntax-with-preg-match/#findComment-466320 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.