- preg_match: documentation ( source)
- print_r: documentation ( source)
<?php
function get_numerics ($str) {
preg_match('/^mom_(\d+)$/', $str, $matches);
return $matches[1];
}
$one = 'mom_5';
$two = 'mom_123';
$three = 'actions';
print_r(get_numerics($one));
print_r(get_numerics($two));
print_r(get_numerics($three));