- substr: documentation ( source)
- preg_match: documentation ( source)
- filter_var: documentation ( source)
<?php
$string = "Reman. 9mm Luger 125 gr. Match";
if(preg_match('/(9mm Luger|40 S&W|45 ACP)(.*Match)/',$string,$matches)){
$power_factor = 175;
}else{
$power_factor = 0;
}
$ammunition = "Reman. 9mm Luger 115 gr. Target";
$grains = filter_var(substr($ammunition,$strcspn($ammunition,"gr")-4,4),FILTER_SANITIZE_NUMBER_INT);
echo '['.$power_factor.'] ['.$grains.']';