Home > Net >  How to drop the first digit in phone number in php
How to drop the first digit in phone number in php

Time:03-10

I want to drop the first digit in phone number in php (for laravel framework). For example, if the user enter 05030123456, I want to get 2335030123456 into the database. That is, if my phone column in the database is phone_number, I will normally have the code in the controller look like this:

$user->phone_number = $request->phone

So, how can I treat $request->phone so it send 2335030123456 to the database for $user->phone_number instead of 05030123456.

CodePudding user response:

If you want predefined ' 233' then below code will be help you.

$user->phone_number = ' 233'.substr($request->phone, 1);

So, your output will be : 2335030123456.

CodePudding user response:

use string manipulation their is Str class in Laravel it's very useful

\Str::replaceFirst('0',' 233', $request->phone)
  • Related