Skip to content

Instantly share code, notes, and snippets.

@lawebfabric
Last active December 1, 2018 15:29
Show Gist options
  • Save lawebfabric/8f0530ae2f62ce3f90769931a7d6c1b6 to your computer and use it in GitHub Desktop.
Save lawebfabric/8f0530ae2f62ce3f90769931a7d6c1b6 to your computer and use it in GitHub Desktop.
A simple snippet that return formated phone number for a html tag
<?php
//-----------------------------------------------------------
// formatPhone
//-----------------------------------------------------------
/*
* @author: Steeve from lawebfabric
* @website: http://www.lawebfabric.com
* @tutorial modx website: http://www.tutocms.fr/
*/
// $input = '04 94 39 28 49';
// $input = '+33 4 56 78 98 76';
// Return formated number like +33456789876
$formated_number = preg_replace('/\s+/', '', $input);
$formated_number = preg_replace('/^0/','+33',$formated_number);
return $formated_number;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment