* json_encode 返回 NULL?不是答案。使用 json_encode 时,我仍然收到 NULL。*
我对 PHP 很陌生,所以如果您可以使用固定代码编辑该部分,我将不胜感激。
这是我的问题:
当“introtext”下的文章包含非断行时,它返回 NULL。没有不间断空格的文章显示得很好。
这是我的问题:
如何让“introtext”下的文章正确显示,即使它们包含非中断空格。
这是代码:
$connection = mysqli_connect($host, $user, $pass);
//Check to see if we can connect to the server
if(!$connection)
{
die("Database server connection failed.");
}else{
//Attempt to select the database
$dbconnect = mysqli_select_db($connection, $db);
//Check to see if we could select the database
if(!$dbconnect)
{
die("Unable to connect to the specified database!");
}else{
$catID = $_GET['catid'];
$id = $_GET['id'];
$rtn = $_GET['rtn'];
if($id!=""){
$query = "SELECT * FROM tcp_content WHERE id=" . $id . "";
}else{
$query = "SELECT * FROM tcp_content WHERE catid=" . $catID . " ORDER BY publish_up DESC LIMIT " . $rtn . "";
}
$resultset = mysqli_query($connection,$query);
$records = array();
//Loop through all records and add them to array
while($r = mysqli_fetch_assoc($resultset))
{
$r['introtext'] = print_r($r['introtext'],true);
$records[] = $r;
}
//Output the data as JSON
echo json_encode($records);
}
}
?>
这里有两个链接: