Skip to content

Instantly share code, notes, and snippets.

@xafarali
Created January 1, 2015 00:01
Show Gist options
  • Save xafarali/2538b96b1a3ec0e6162f to your computer and use it in GitHub Desktop.
Save xafarali/2538b96b1a3ec0e6162f to your computer and use it in GitHub Desktop.
Replace Numbers with Pattern
$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