I am using the Google Drive API and the refresh_token
I obtain has an escaped forward slash. While this should be valid JSON, the API won't accept it when calling refreshToken()
. I am trying to remove the backslash using preg_replace
:
$access_token = "1\/MgotwOvbwZN9MVxH5PrLR2cpvX1EJl8omgYdA9rrjx8";
$access_token = preg_replace('/\\\//', '/', $access_token);
I would like the returned string to be:
"1/MgotwOvbwZN9MVxH5PrLR2cpvX1EJl8omgYdA9rrjx8";
I've tried various expressions, but it either doesn't remove the backslash or it returns an empty string. Note that I don't want to remove all backslashes, only the ones escaping a forward slash.
Avoid regex and just use str_replace
:
$access_token = "1\/MgotwOvbwZN9MVxH5PrLR2cpvX1EJl8omgYdA9rrjx8";
$access_token = str_replace( '\/', '/', $access_token );
//=> 1/MgotwOvbwZN9MVxH5PrLR2cpvX1EJl8omgYdA9rrjx8
Well, there's a standard function that does just that: stripslashes
So please avoid regex, str_replace et al.
It's as simple as it takes:
$access_token = stripslashes($access_token);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With