Skip to content

Instantly share code, notes, and snippets.

@xafarali
Created January 1, 2015 00:01
Show Gist options
  • Select an option

  • Save xafarali/2538b96b1a3ec0e6162f to your computer and use it in GitHub Desktop.

Select an option

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