Created
May 19, 2014 13:32
-
-
Save cagartner/38e0d9a696458d7fae4d to your computer and use it in GitHub Desktop.
Formatar placa de carros, caminhões e motos do Brasil
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function formatarPlaca($placa) { | |
| $placa = str_replace('-', '', strtoupper($placa)); | |
| return preg_filter('/^([a-zA-Z]{3})(\d{3,7})$/', '$1-$2', $placa); | |
| } | |
| echo formatarPlaca('mhu2913'); | |
| // MHU-2913 | |
| echo formatarPlaca('mhu-2913'); | |
| // MHU-2913 | |
| echo formatarPlaca('MHU2913'); | |
| // MHU-2913 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment