Created
January 1, 2015 00:01
-
-
Save xafarali/2538b96b1a3ec0e6162f to your computer and use it in GitHub Desktop.
Replace Numbers with Pattern
This file contains 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
$num = 123; | |
$format = 'ABC-####-09'; | |
print preg_replace('/(#+)/e', 'str_pad($num, strlen("$1"), 0, STR_PAD_LEFT)', $format); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment