php 幾種編碼 解碼

1.json_encode和json_decodephp

<?php
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($json));
var_dump(json_decode($json, true));
?>

object(stdClass)#1 (5) {
    ["a"] => int(1)
    ["b"] => int(2)
    ["c"] => int(3)
    ["d"] => int(4)
    ["e"] => int(5)
}
array(5) {
    ["a"] => int(1)
    ["b"] => int(2)
    ["c"] => int(3)
    ["d"] => int(4)
    ["e"] => int(5)
}

2.base64_decode和base64_encodejson

 <?php
  $str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';
  echo base64_decode($str);
  ?>
  此示例將顯示:
  This is an encoded string[1]
相關文章
相關標籤/搜索