ddw_0_op1
ddw_1_op1
ddw_2_op1
ddw_3_op1
ddw_4_op1
in these strings of array how i can extract or preg_match only the number in middle that increase . t
use the preg_match function:
$str = "ddw_01_fdfd";
preg_match('/.+_([0-9]+)_.+/', $str, $matches);
echo $matches[1];
Output:
01
Another way to do it is by explode the string by _
:
$xpl = explode('_', $str);
$middleStr = $xpl[1];
The explode function splits a string by string, in that case create an array made by all substring contained in $str
dividing them by _
.
Try it here.