javascript - strip white spaces from php file -


i have php file outputing json.

<?php     header('content-type: application/json'); ?> var data = {     "cars": [     <?php foreach ($runshowcars $rowscar):;?>         {             "id":"<?php echo $rowscar['id'] ?>",             "name":"<?php echo $rowscar['name'] ?>"         }     ],     "boats": [     <?php foreach ($runshowboats $rowsboat):;?>         {             "id":"<?php echo $rowsboat['id'] ?>",             "name":"<?php echo $rowsboat['name'] ?>"         }     ],   }; 

this works output looks this.

                        var data = {         "cars": [         {             "id":"1",             "name":"ford"         }         ,{             "id":"2",             "name":"honda"         }         ]         }; 

i want this.

var data = {"cars": [{"id":"1","name":"ford"},{"id":"2","name":"honda"}]}; 

the way have found remove white spaces php file, not ideal solution makes hard maintain.

how can strip out white spaces here?

i have seen plenty of questions one, how minify php page html output? can't working here data isn't in variable?

why don't collect data array , encode json.

like this:

$data=array('cars'=>$runshowcars, 'boats'=>$runshowboats); print json_encode($data); 

(otherwise return javascript, , not json. @ least if prepend result var data = part.)


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -