There's a bunch of different ways you could do this... sometimes you just have to stop and put on your creativity hat.
Something like this would work (but might not be the best solution):
$rand = rand(1, 100);
if($rand >= 1 && $rand <= 20) {
$attack = 0;
}
else {
$attack = 1;
}
// use the $attack var wherever in your script to indicate hit or miss