把destoon資料生成json,一般用于百度小程式、QQ小程式和微信小程式或者原生APP,由于系統是GB2312編碼,所以服務端撰寫的時候我們進行了一些編碼轉換的處理,保證服務端訪問的編碼是UTF-8就可以,不多了,下面干貨來了,如果你是程式或此段代碼對你有幫助,希望收藏!!
代碼來了,在根目錄新建一個檔案夾,如appapi ,在其下面建一個php檔案,如api.php 放入以下代碼
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php
header("Content-Type: text/html;charset=utf-8");
define('DT_REWRITE', true);
require '../common.inc.php';
$lists = array();
//展示欄目下的子欄目;
if(!empty($areaid)){
if(!$AREA[$areaid]["parentid"]){
$condtion="and areaid in (".$AREA[$areaid]["arrchildid"].")";
$condtions="areaid in (".$AREA[$areaid]["arrchildid"].")";
}else{ $condtion="and areaid=$areaid"; $condtions="areaid=$areaid"; }
}
//echo列印destoon資料;
if(empty($areaid)) {
$sql_brand="select itemid,areaid,catid,title,company,hits,edittime,thumb(這些是調取的欄位) from destoon_brand_13(這里是表名) order by hits desc limit 0,14";
}
//$sql_brand="select *(*表示表里所有的欄位) from destoon_brand_13(這里是表名) order by hits desc limit 0,14";
$result=$db->query($sql_brand);
while($r = $db->fetch_array($result)) {
$lists[] = $r;
}
$str=json_encode($lists);
$str= preg_replace("#\\\u([0-9a-f]+)#ie","iconv('UCS-2','UTF-8', pack('H4', '\\1'))",$str);
echo $str;
?>
|
本文來自博客園,作者:考高分網,轉載請注明原文鏈接:http://www.kaotop.com/
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/477641.html
標籤:PHP
上一篇:php命名空間
