Home > Backend Development > PHP Tutorial > php转js dom格式怎么做

php转js dom格式怎么做

WBOY
Release: 2016-06-13 10:46:13
Original
897 people have browsed it

php转js dom格式如何做?
数据库字段 shopinfo 里信息是这样的

绿色@@@/A/11/12/13/@@@/B/21/22/23/###蓝色@@@/A/31/32/33/@@@/B/41/42/43/###绿色@@@/A/51/52/53/@@@/B/61/62/63/

怎么样才能变化成这样的格式呢




------解决方案--------------------
json_encode($arr); //数组转json
------解决方案--------------------

PHP code
$s="黑色@@@/A/11/12/13/@@@/B/21/22/23/###红色@@@/A/31/32/33/@@@/B/41/42/43/###绿色@@@/A/51/52/53/@@@/B/61/62/63/";foreach(explode('###',$s) as $v){  $arr = explode('@@@/',$v);  $k = array_shift($arr);  $p = $q = array();  foreach($arr as $r) {    $t = explode('/', trim($r, '/'));    $p[] = array_shift($t);    $q[] = $t;  }  $ar[$k] = array_merge(array($p), $q);  }print_r($ar);<br><font color="#e78608">------解决方案--------------------</font><br>中文丢失,是因为不是 utf-8 编码的原因<br><br>连接数据库后,执行<br>mysql_query('set name utf8');<br>即可在其后取得 utf-8 编码的数据,再做成 json 就没有问题了<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template