Running a simple search query, which feeds into an android studio textview. When I first managed to display results via .php site, all special characters ([{]}) were on show, but i added this line to remove:
echo json_encode($resultArray, DEFINED('JSON_INVALID_UTF8_IGNORE') ? JSON_INVALID_UTF8_IGNORE : 0);
However, this now means that the results that show are also missing special characters, mainly " ' ". So "You're", is actually showing "Youre".
I have tried to play with the above json query, but with no luck - any idea what I'm doing wrong?
Full code for clarity:
<?php
// Create connection
$con=mysqli_connect("server","user","pass","table");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Select all of our stocks from table 'stock_tracker'
$sql = "
SELECT Task_title
, task_description
FROM TASKS
ORDER
BY RAND () ASC
LIMIT 1
";
// Confirm there are results
if ($result = mysqli_query($con, $sql))
{
// We have results, create an array to hold the results
// and an array to hold the data
$resultArray = array();
$tempArray = array();
// Loop through each result
while($row = $result->fetch_object())
{
// Add each result into the results array
$tempArray = $row;
array_push($resultArray, $tempArray);
}
// Encode the array to JSON and output the results
echo json_encode($resultArray, DEFINED('JSON_INVALID_UTF8_IGNORE') ? JSON_INVALID_UTF8_IGNORE : 0);
echo json_last_error_msg(); // Print out the error if any
die(); // halt the script
}
// Close connections
mysqli_close($con);
?>