PHP内置的编码函数有很多,下面列举一些常用的函数及其用法:
-
base64_encode():将字符串进行Base64编码。 用法:$encodedString = base64_encode($string);
-
base64_decode():将Base64编码的字符串进行解码。 用法:$decodedString = base64_decode($encodedString);
-
urlencode():对URL中的特殊字符进行编码。 用法:$encodedString = urlencode($string);
-
urldecode():对URL中的特殊字符进行解码。 用法:$decodedString = urldecode($encodedString);
-
htmlentities():将字符串中的特殊字符转换为HTML实体。 用法:$encodedString = htmlentities($string);
-
html_entity_decode():将HTML实体还原为原始字符。 用法:$decodedString = html_entity_decode($encodedString);
-
json_encode():将PHP对象或数组转换为JSON字符串。 用法:$jsonString = json_encode($data);
-
json_decode():将JSON字符串转换为PHP对象或数组。 用法:$data = https://www.yisu.com/ask/json_decode($jsonString);
这些函数可以根据具体的需求选择使用,用于对字符串、URL、HTML实体和JSON数据进行编码和解码操作。