以JSON格式转义HTML实体

时间:2014-05-26 07:24:51

标签: php json

我的JSON结果http://daysof.me/lowyat/list.php

我做了什么:

$num = 0;
$array = array();
foreach($rows as $go){

    if($num == count($rows)-1){break;}

    $reply = $go->find('td',3)->plaintext;//replies
    $starter = $go->find('td',4)->plaintext;//starter
    $views = $go->find('td',5)->plaintext;//views
    $action = $go->find('td',6)->plaintext;//last action
    $desc = $go->find('td',2)->find('div div',2)->plaintext;//description
    $title = $go->find('td',2)->find('div div a',0)->plaintext;//topic name
    $link = $go->find('td',2)->find('div div a',0)->href;

    $array[]= array(
        'title'=>$title,
        'desc'=>$desc,
        'starter'=>trim($starter),
        'replies'=>trim($reply),
        'url'=>'https://forum.lowyat.net'.$link
    );

    $num ++;
}

echo json_encode($array);

您会看到某个单引号已变为",并且&符号会给出奇怪的代码。

我怎么能逃脱呢?我试过'title'=>htmlentities($title)仍然没有运气。

0 个答案:

没有答案