php中屡试不爽的数组和json

  • json_encode与json_decode
  • urlencode与urldecode
  • addslashes与stripslashes
  • addcslashes与stripcslashes
  • 以上这些请自行了解

附上两组操作实例

  1. 实例一,借助urlencode函数

    function arrayRecursive(&$array, $function, $apply_to_keys_also = false)
    {
    static $recursive_counter = 0;
    if (++$recursive_counter > 1000) {
    die('possible deep recursion attack');
    }
    foreach ($array as $key => $value) {
    if (is_array($value)) {
    arrayRecursive($array[$key], $function, $apply_to_keys_also);
    } else {
    $array[$key] = $function($value);
    } if ($apply_to_keys_also && is_string($key)) {
    $new_key = $function($key);
    if ($new_key != $key) {
    $array[$new_key] = $array[$key];
    unset($array[$key]);
    }
    }
    }
    $recursive_counter--;
    } function my_json($array) {
    arrayRecursive($array, 'urlencode', true);
    $json = json_encode($array);
    return urldecode($json);
    }
    $arr = [
    'a' => 123,
    'b' => 456,
    'http://www.jjxhp.com/abc/sasa.php' => 'tstst你好',
    'http://www.baidu.com/' => '我们都是好人吧',
    'rew你好' => 'dsdsqwq'
    ]; $str = my_json($arr); file_put_contents(__DIR__.'/json_str.txt', $str);
  2. 实例二,借助 json_encode与stripslashes

    $new_str = json_encode($arr, JSON_UNESCAPED_UNICODE);
    file_put_contents(__DIR__.'/new_json_str.txt', $new_str);
    $new_str1 = stripslashes($new_str);
    file_put_contents(__DIR__.'/new_json_str1.txt', $new_str1);

附言

  • htmlentities与htmlspecialchars也脑补吧,自己感觉真的很好用,嘻嘻!!

最新文章

  1. 【C++沉思录】句柄2
  2. PE文件结构部分解析以及输入的定位
  3. PDA手持终端在ERP系统仓库管理出入库盘点环节的应用
  4. hdoj 1231 最大连续子序列
  5. 在使用Kettle的集群排序中 Carte的设定——(基于Windows)
  6. Assumptions
  7. Tomcat配置一个ip绑定多个域名
  8. Oracle中的单引号问题
  9. all about AIX MPIO
  10. JMS分布式应用程序异步消息解决方案EhCache 高速缓存同步问题
  11. 手机端仿ios的省市县3级联动脚本一
  12. Elasticsearch系列(5):深入搜索
  13. MYSQL数据库常用操作命令
  14. AT2412 最大の和
  15. MobX基础 ----- 类的静态属性和装饰器
  16. Synchronized和java.util.concurrent.locks.Lockde区别联系
  17. Class__Two
  18. Sprint最后一天
  19. linux修改文件所有者和文件所在组
  20. DPDK报文分类与访问控制

热门文章

  1. 如何系统的了解Kafka
  2. XXL-JOB v2.3.0 发布 | 易用性增强
  3. vue修改elementUI的分页组件视图没更新问题
  4. 翻译:《实用的Python编程》03_04_Modules
  5. PAT-1043(Is It a Binary Search Tree)JAVA实现
  6. LeetCode-[list-of-depth-lcci]
  7. web服务器-并发服务器2
  8. WPF 基础 - 绘画 2) Path
  9. 02-Spring配置文件加载
  10. Less常用变量与方法记录