I need some code for a PHP project. I need to correct mobile number formats that we receive incorrectly on occasion into our API. If the number starts with +270 then it needs to be replaced with 27 and still preserve the rest of the number
Asked
Active
Viewed 34 times
-1
-
Already voted to close as Too Broad, but this also appears to be a duplicate: https://stackoverflow.com/questions/12605060/how-do-i-replace-part-of-a-string-in-php – David Jun 10 '19 at 19:45
-
4Ok, go ahead. What do you need us for? – Jun 10 '19 at 19:45
-
Sounds like a nice challenge. Good luck! – fonZ Jun 10 '19 at 19:46
-
how is this to broad? – code-is-life Jun 10 '19 at 19:54
-
I know @Dharman but I figured (guessed) it was probably at the start of the string and the + wasn't likely to be repeated. – Dave Jun 10 '19 at 19:56
-
yes so I only need to replace at the start of the string and only if it matches exactly +270 – code-is-life Jun 10 '19 at 19:57
-
@code-is-life Could you read this section, please? [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – Dharman Jun 10 '19 at 20:01
1 Answers
1
$phoneNumber = preg_replace("(^\+270)", "27", $phoneNumber);
Simple as that.

Lulceltech
- 1,662
- 11
- 22