php如何将下面语句改成字符串?

kpym 发布于 2014/01/20 14:53
阅读 202
收藏 0
PHP

  • $mystr = "date"=>"".iconv('gb2312','utf-8',$rs->Fields['dateb']->Value)."",
    "title"=>"".iconv('gb2312','utf-8',$rs->Fields['title']->Value)."",
    "sper"=>"".iconv('gb2312','utf-8',$rs->Fields['sper']->Value)."" ;


    上面这句是错的,我想把 = 号右边的语句能正确赋予左边的变量。
    右边的赋值是这种格式的:
    'date'=>'2013-7-25','title'=>'标题','sper'=>'操作员' ;

加载中
0
Tuesday
Tuesday
$mystr = array("date"=>"".iconv('gb2312','utf-8',$rs->Fields['dateb']->Value)."",
 "title"=>"".iconv('gb2312','utf-8',$rs->Fields['title']->Value)."",
 "sper"=>"".iconv('gb2312','utf-8',$rs->Fields['sper']->Value)."");
0
kpym
kpym

引用来自“Tuesday”的答案

$mystr = array("date"=>"".iconv('gb2312','utf-8',$rs->Fields['dateb']->Value)."",
 "title"=>"".iconv('gb2312','utf-8',$rs->Fields['title']->Value)."",
 "sper"=>"".iconv('gb2312','utf-8',$rs->Fields['sper']->Value)."");

其实我也是这样做的,无奈我这句是在一个循环里面的。如果是这样写的话,我到最后只输出最后一条记录。

$mystr = "";
 $rs = $conn->Execute('SELECT * FROM score order by dateb desc');
     while(!$rs->EOF) 
            { 

    $mystr = array("date"=>"".iconv('gb2312','utf-8',$rs->Fields['dateb']->Value)."", 
 "title"=>"".iconv('gb2312','utf-8',$rs->Fields['title']->Value)."", 
 "sper"=>"".iconv('gb2312','utf-8',$rs->Fields['sper']->Value)."");

$rs->MoveNext();
 foreach ( $mystr as $key => $value ) {  
        $mystr[$key] = urlencode ( $value );  
    }  
   echo urldecode ( json_encode ( $mystr) );  

0
Tuesday
Tuesday

$mystr[] =

换成这样.

返回顶部
顶部