Reputation: 2079
I am trying to pull event data into my full calendar using php. I have successfully retrieved the data from the database and converted it to json but I have one problem.
Here is the json outputted:
[
{"id":"53","start":"2013-06-06","title":"Assignment2"},
{"id":"52","start":"2013-06-07","title":"Assignment1"},
{"id":"54","start":"2013-06-08","title":"Assignment3"}
]
So when I want to put it into my fullcalendar i do this:
var class_id = $("#calendar").attr('c_id');
$("#calendar").fullCalendar({
dayClick:function(data){
},
events: '/classes/get_due_dates/'+c_id
});
When I did this nothing was showing up on the calendar but when I copied and pasted the output and removed the quotes surrounding id, start and title it worked fine
Like so:
[
{id:"53",start:"2013-06-06",title:"Assignment2"},
{id:"52",start:"2013-06-07",title:"Assignment1"},
{id:"54",start:"2013-06-08",title:"Assignment3"}
]
Notice the quotes removed, So my question is how do i convert the output that I am getting and remove those quotes so I can display these events on my calendar?
Thanks!
Upvotes: 0
Views: 447
Reputation: 11171
Try this if it is what you are looking for.
<?php
$str = '[
{"id":"53","start":"2013-06-06","title":"Assignment2"},
{"id":"52","start":"2013-06-07","title":"Assignment1"},
{"id":"54","start":"2013-06-08","title":"Assignment3"}
]';
$str = str_replace('{"', '{', $str);
$str = str_replace('":', ':', $str);
$str = str_replace(',"', ',', $str);
echo "<pre>" . $str . "</pre>";
?>
Upvotes: 1