php - preg_match/regex format needed -


i have below post fields submitted , trying value of each of numbers in form field quantity. can me regexp? trying each of numbers in variable.

format

quantity_{category}_{product}_{item} 

post fields submitted

[submitted] => 1 [quantity_12038_16061_24960] => 1 [quantity_12037_16060_24959] => 2 [btnbuynow] => next step 

php code

foreach ($_post $key => $value) {     if (preg_match('/^quantity_(\d+)$/', $key, $matches)) {         echo 'key:' . $key . '<br>';         echo 'matches:' . $matches . '<br>';         echo '<hr>';     } } 

use preg_match() docs purpose, , sample of how code like:

$subject="quantity_12038_16061_24960"; $pattern='/quantity_(\d+)_(\d+)_(\d+)/'; preg_match($pattern, $subject, $matches);  echo $matches[0]; //12038 {category} echo $matches[1]; //16061 {product} echo $matches[2]; //24960 {item} 

you can see how regex performing here.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -