Egypt’s Mobile Number Change

11.06.2011 | PHP

I’ve developed a snipped to correct the old numbers with the new numbers

The number change schema as follows:

(old -> new)

Mobinil

012 XXX XXXX -> 0122 XXX XXXX
017 XXX XXXX -> 0127 XXX XXXX
018 XXX XXXX -> 0128 XXX XXXX
0150 XXX XXXX -> 0120 XXX XXXX

Etisalat

011 XXX XXXX -> 0111 XXX XXXX
014 XXX XXXX -> 0114 XXX XXXX
0152 XXX XXXX -> 0112 XXX XXXX

Vodafone

010 XXX XXXX -> 0100 XXX XXXX
016 XXX XXXX -> 0106 XXX XXXX
019 XXX XXXX -> 0109 XXX XXXX
0151 XXX XXXX -> 0101 XXX XXXX

so here is my little php function that will use regular expressions

function changeMobileNumbers(&$contents){
	// vodafone
	$contents = preg_replace('/(0151)([0-9]{7})/', '0101$2', $contents);
	$contents = preg_replace('/(010)([0-9]{7})/', '0100$2', $contents);
	$contents = preg_replace('/(016)([0-9]{7})/', '0106$2', $contents);
	$contents = preg_replace('/(019)([0-9]{7})/', '0109$2', $contents);
	
	// etisalat
	$contents = preg_replace('/(0152)([0-9]{7})/', '0112$2', $contents);
	$contents = preg_replace('/(011)([0-9]{7})/', '0111$2', $contents);
	$contents = preg_replace('/(014)([0-9]{7})/', '0114$2', $contents);
	
	// mobinil
	$contents = preg_replace('/(0150)([0-9]{7})/', '0120$2', $contents);
	$contents = preg_replace('/(012)([0-9]{7})/', '0122$2', $contents);
	$contents = preg_replace('/(017)([0-9]{7})/', '0127$2', $contents);
	$contents = preg_replace('/(018)([0-9]{7})/', '0127$2', $contents);
	return $contents;
}

Hope that was useful

Be Sociable, Share!

Responses

Amr El Sherif
12.02.2011

Very helpful indeed!

Mahmoud
7.11.2012

Hello i hope this comment be helpful like your post
if you use
look around “http://www.regular-expressions.info/lookaround.html”
in regex i think it will reduce 5 lines
ex:
preg_replace(‘/(01(?=0|6|9))([0-9]{8})/’,’010$2′,$contents);

and if you use
preg_replace_callback
it will be better

“sorry if i disturbed you”

Comments