我想將從數據庫檢索到的數據編碼到json中。這裏是我的代碼..var_dump顯示正確的數組,但json_encode函數嘗試編碼相同的數組時返回false
<?php
$con = mysqli_connect("localhost", "root", "", "joomla");
if($con === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = "SELECT * FROM yv084_content";
$result = mysqli_query($con, $sql);
$all_result = array();
$intro_result = array();
$num_rows = mysqli_num_rows($result);
$count =0;
while($row = mysqli_fetch_assoc($result)){
$all_result[] = $row;
}
while($count<$num_rows){
$intro_result[] = strip_tags($all_result[$count]['introtext']);
//echo strip_tags($all_result[$count]['introtext'])."<hr />";
$count++;
}
echo "<hr />";
var_dump($intro_result);
echo "<hr />";
$encoded_value = json_encode($intro_result);
var_dump($encoded_value);
echo $encoded_value;
當我使用var_dump
功能,然後我得到正確的結果,但是當我使用json_encode
功能編碼陣列它返回假的..是否有任何想法如何對其進行編碼..
注意:有很多特殊字符和html實體,所以我使用strip_tags
函數。
請查看結果我在瀏覽器中得到了...
Screenshot of browser's result
可以粘貼在這裏'的var_dump($ intro_result)的結果;'這裏好嗎? –
是的,只是給出數組的結果,所以我們可以找到你的東西 –