Skip to content

Instantly share code, notes, and snippets.

@Semdevmaster
Created March 26, 2018 10:58
Show Gist options
  • Select an option

  • Save Semdevmaster/b93c54bf7b05a79ead83087813128cfa to your computer and use it in GitHub Desktop.

Select an option

Save Semdevmaster/b93c54bf7b05a79ead83087813128cfa to your computer and use it in GitHub Desktop.
<?php
$input_without_spaces = trim($input);
$pattern = '/^(\d)(\d{3})(\d{3})(\d{2})(\d{2})$/';
$replacement = '8 (\2) \3-\4-\5';
return $output = preg_replace($pattern, $replacement, $input_without_spaces);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment