I don't know if it's a lame solution, but my idea would be to do the following :
1) Make a string containing chars that a valid in your passwords
2) For each of the chars in the string, count the number of times the char is found in the password (substr_count)
Then make sure if your rules are obeyed. If not, password is bad, else it's okay.
Just an idea - if you need an example, feel free to contact me.