I have a php file where I am outputing json.
<?php
header('Content-Type: application/json');
?>
var data = {
"cars": [
<?php foreach ($runshowcars as $rowscar):;?>
{
"id":"<?php echo $rowscar['id'] ?>",
"name":"<?php echo $rowscar['name'] ?>"
}
],
"boats": [
<?php foreach ($runshowboats as $rowsboat):;?>
{
"id":"<?php echo $rowsboat['id'] ?>",
"name":"<?php echo $rowsboat['name'] ?>"
}
],
};
This works however the output looks like this.
var data = {
"cars": [
{
"id":"1",
"name":"Ford"
}
,{
"id":"2",
"name":"Honda"
}
]
};
I want it to look like this.
var data = {"cars": [{"id":"1","name":"Ford"},{"id":"2","name":"Honda"}]};
The only way I have found to do this is to remove the white spaces from my php file, this is obviously not an ideal solution as it makes it very hard to maintain.
How can strip out all the white spaces here?
I have seen plenty of questions like this one, How to minify php page html output? however I can't get something like this working here as my data isn't in a variable?