ali_2kool2002 Posted April 14, 2007 Share Posted April 14, 2007 Hi can someone tell me how the code below works? im not sure what preg_match does with all those characters after it ? ??? ??? foreach ($_POST as $k => $v) { if (preg_match('|^sub_([\d]+)\z|', $k, $match)) { $button = $match[1]; Quote Link to comment https://forums.phpfreaks.com/topic/47029-solved-explanation-of-code/ Share on other sites More sharing options...
Guest prozente Posted April 14, 2007 Share Posted April 14, 2007 |^sub_([\d]+)\z| | is the pattern delimiter ^ means from the start of the string sub_ is some text it wants to match from the start of the string () are used to create back references, it'll capture this text in the returned array [] are used to define a character class \d stands for decimal digit, it'll match numbers 0-9, so this is the character class + means the character class will match at least one char for a char class so ([\d]+) will be returned as the first back reference \z stands for the end of the string so sub_123 will pass this regex and return 123 as the first back reference sub_abc1 will not pass this regex as it has the alpha characters in it Quote Link to comment https://forums.phpfreaks.com/topic/47029-solved-explanation-of-code/#findComment-229378 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.