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