我有以下perl代码:
my $pin = <get PIN from submitted web page data>
return “Error” if !defined($pin);
$pin = &trimAndUpper($pin);
# Test for length validity.
return “Error” unless length($pin) == 8;
# Test for hex validity.
return “Error” unless ($pin =~ /^[[:xdigit:]]+$/);
# Good PIN at this point.
sub trimAndUpper {
my ($str) = @_;
$str =~ s/^\s+//; # left trim
$str =~ s/\s+$//; # right trim
$str =~ tr/a-z/A-Z/; # to upper
return $str;
}
我无法将其转换为PHP,有人可以帮忙吗?