您好我正在使用函数 json_encode 通过关联数组从数据库中检索数据。但是我想问一下如何将 img 标签转换为字符串并将其放入关联数组中,然后让 json 对其进行编码并吐出所有内容,同时将 img 标签保持为字符串?
while($row=$result->FetchRow())
{
$id= (float)$row['id'];
$name = $row['name'];
$color1 = $row['color'];
$type1 = $row['type'];
$to= (float)$row['to'];
$thumb =$row['thumb']; //image path
$array = array(
"adjacencies" => array( array(
"nodeTo" => "$to",
"nodeFrom" => "$id",
"data" => array() )),
"data" => array(
"$"."color" => $color1,
"$"."type" => $type1 ),
"id" => $id,
"name" => "<img src='$thumb' height='30' width='30' alt='root'/><label>$name</label> ");
}
$json = json_encode($array);
print "$json";
return $json;