php - How to pull numbers from a string with curly brackets? -


i have test string this:

digit{digit}digit 

i want break string 3 variables. example, 40{1}2 should split 40 1 2. string big 2034{345}1245. assume regex best way split string.

here's have far:

$productid = preg_match('/(.*?){/', $product); $productoptionid = preg_match('/{(.*?)}/', $product); $optionvalueid = preg_match('/}(.*?)/', $product); 

no need regular expressions here:

$str = '40{1}2';  sscanf($str, '%d{%d}%d', $part_1, $part_2, $part_3); // $part_1 equal: 40 // $part_2 equal: 1 // $part_3 equal: 2 

with method, variables typecast integers.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -