Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ShieldsOnTour's avatar

$request->input() removing "+" from POST'd international phone numbers

Hi all,

I'm pretty sure that this is me being 100% dumb - its now into hour 20 of coding...

I'm posting International phone numbers from an API bridge to my Laravel App - but when I retrieve the number from the Request it has the "+" replaced with " ".

So, for example, if I POST "+4480012345678" the Laravel Request input is " 4480012345678"

V. frustrating.

What's the really dumb thing I'm not going please!

Thanks

0 likes
3 replies
ShieldsOnTour's avatar

I'll try the urlencode/devode stuff - see if that's what is causing it all.

For the moment, I've used this lib:-

https://github.com/giggsey/libphonenumber-for-php

to ensure that the number is stored in my DB as E164 format international number, which with hindsight is probably the more robust solution anyway :)

Snapey's avatar

How are you doing the POST?

Its common URLs have spaces converted to + symbols when passed as URI parameters

Route::get('/account', function () {

    $phone = Input::get('phone');
    return response()->json(['data'=>$phone]);
});

Then, when you call http://localhost:8000/account?phone=+123456, the output is;

{
data: " 123456"
}

This is because it is assumed that the plus symbol is a substitute for a space.

You can avoid this by encoding the plus with %2b , ie http://localhost:8000/account?phone=%2b123456

{
data: "+123456"
}

Please or to participate in this conversation.