0

I am trying to get JSON response using PHP. I want to have Json array not the HTML tags. But the output shows HTML tags as well.I want to remove this HTML output! PHP code is as follows: I don't know how to do this ? Please help. Thanks in advance :)

<?php
function getFixture(){
$db = new DbConnect();
// array for json response of full fixture
$response = array();
$response["fixture"] = array();
$result = mysql_query("SELECT * FROM fixture"); // Select all rows from fixture table
while($row = mysql_fetch_array($result)){
    $tmp = array();        // temporary array to create single match information
    $tmp["matchId"] = $row["matchId"];
    $tmp["teamA"] = $row["teamA"];
    $tmp["teamB"] = $row["teamB"]; 
    array_push($response["fixture"], $tmp);
}

header('Content-Type: application/json');
echo json_encode($response);
}

getFixture();
?>
4

1 回答 1

0

如果没有看到您的输出是很难判断的,但是您的代码中没有任何内容可以将 HTML 添加到您的响应中。

听起来 HTML 在数据库中,因此您可以按预期获取数据,并且您的浏览器正在显示可能存在的任何 html 元素。

您可以使用以下方法确保数据库中的所有行都不包含 HTML strip_tags

    $tmp["teamA"] = strip_tags($row["teamA"]);

对所有可能包含 html 的行执行此操作。

抱歉,如果格式不正确,我是 StackOverflow 的新手! http://php.net/strip-tags

于 2015-02-25T15:30:42.500 回答