I make a curl request to a server which returns javascript and I need to get each of the addNewEvent functions returned into a PHP array. So I figured I would use preg_match_all.
Unfortunately regex is not my strong point and I keep getting it wrong. Could someone please help me out with this?
I have this so far:
'/addNewEvent\(\{(.*)\}\);/s'
This is a snippet from the javascript containing the functions I need. The rest of the javascript does contain if statements with braces:
addNewEvent({id:2, type:1,
start: new Date(2012,02-1,10,09,00),
end:new Date(2012,02-1,10,10,00),
startRounded:new Date(2012,1,10,9,0),
endRounded:new Date(2012,1,10,10,0),
desc:"test", allDay:0, recurring:0, reminder:0,
comment:"this is a tes\\\'st\\\"",
labelColor:\'#FF9281\', numOverlaps:0, overlapNumber:0});
addNewEvent({id:3, type:1,
start: new Date(2012,02-1,10,09,00),
end:new Date(2012,02-1,10,10,00),
startRounded:new Date(2012,1,10,9,0),
endRounded:new Date(2012,1,10,10,0),
desc:"test 2", allDay:0, recurring:0, reminder:0,
comment:"",
labelColor:\'#849CE7\', numOverlaps:0, overlapNumber:0});
Thanks in advance.
Edit 13:23
Ideally I would like to have returned an array containing the JSON objects from inside the javascript function calls:
array(
[0] => '{id:2, type:1,
start: new Date(2012,02-1,10,09,00),
end:new Date(2012,02-1,10,10,00),
startRounded:new Date(2012,1,10,9,0),
endRounded:new Date(2012,1,10,10,0),
desc:"test", allDay:0, recurring:0, reminder:0,
comment:"this is a tes\\\'st\\\"",
labelColor:\'#FF9281\', numOverlaps:0, overlapNumber:0}',
[1] => '{id:3, type:1,
start: new Date(2012,02-1,10,09,00),
end:new Date(2012,02-1,10,10,00),
startRounded:new Date(2012,1,10,9,0),
endRounded:new Date(2012,1,10,10,0),
desc:"test 2", allDay:0, recurring:0, reminder:0,
comment:"",
labelColor:\'#849CE7\', numOverlaps:0, overlapNumber:0}'
);