devWhiz Posted April 28, 2011 Share Posted April 28, 2011 if I have this info in a doc " id="r4_20770702"> how would I use preg_match or preg_match_all to parse ot the number 20770702 and would it be different to parse ot more than one id in that form like... " id="r4_20770702"> " id="r4_35133964"> " id="r4_38461866"> " id="r4_31859736"> Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted April 28, 2011 Share Posted April 28, 2011 Assuming r4_ is always there, then this might work: preg_match_all('/id="r4_([\d]+)">/', $string, $matches); print_r($matches[1]); Other variations depending on the formats. Quote Link to comment Share on other sites More sharing options...
devWhiz Posted April 28, 2011 Author Share Posted April 28, 2011 yep r4 is the same all the time, Thanks man! I aqppreciate the help, it worked I need to learn preg match.. It would help out alot for the stuff I do, any tips? Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted April 28, 2011 Share Posted April 28, 2011 This is a good source: http://www.regular-expressions.info/ Also, there are quite a few online regex testers: http://www.myregextester.com/index.php Quote Link to comment Share on other sites More sharing options...
.josh Posted April 28, 2011 Share Posted April 28, 2011 couple things to note about the pattern AbraCadaver provided: preg_match_all('/id="r4_([\d]+)">/', $string, $matches); \d doesn't have to be wrapped in a character class, it's kind of it's own character class, so you can just do \d+ But \d technically matches more than numbers, so if you want to be more specific, use [0-9] instead: preg_match_all('/id="r4_([0-9]+)">/', $string, $matches); Quote Link to comment 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.