The method of URL secure string Encoding and Decoding in PHP
This article introduces the relevant knowledge of "URL secure string encoding and decoding methods in PHP". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
If you use the base64_encode and base64_decode methods directly, the resulting string may not apply to the URL address. The following methods can solve this problem:
URL secure string encoding:
The copy code is as follows:
Function urlsafe_b64encode ($string) {
$data = base64_encode ($string)
$data = str_replace (array ('+','/','='), array ('-','_','), $data)
Return $data
}
URL secure string decoding:
The copy code is as follows:
Function urlsafe_b64decode ($string) {
Data = str_replace (array ('-','_'), array ('+','/'), $string)
$mod4 = strlen ($data) 4
If ($mod4) {
$data. = substr ('=, $mod4)
}
Return base64_decode ($data)
}
This is the end of the content of "URL secure string Encoding and Decoding methods in PHP". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!