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();
?>
Stack
  • 1

1 Answers1

0

It's difficult to tell without seeing what your output is, but there is nothing in your code which would add HTML to your response.

It sounds like the HTML is in the database, so you're getting the data as expected, and your browser is the displaying whatever html elements might be there.

You could ensure none of the rows from the database have HTML in them by using strip_tags as follows:

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

Do this for all rows which may contain html.

Sorry if this is not formatted right, I'm new to StackOverflow! http://php.net/strip-tags

markmoxx
  • 1,492
  • 1
  • 11
  • 21