做一个destoon输出json的api,用于数据调用
作者:互联网
把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 ;
?>
|
标签:areaid,destoon,brand,hits,json,api,str 来源: https://www.cnblogs.com/68xi/p/16281477.html