3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php define('APPKEY','XXXXXXXXXXXXXXX'); // Your app key define('PUSHSECRET', 'XXXXXXXXXXXXXXX'); // Your master Secret define('PUSHURL', 'https://go.urbanairship.com/api/push/'); $iosspecific = array(); $iosspecific['badge'] = "+1"; $iosspecific['sound'] = "cat.caf"; $notification = array(); $notification['alert'] = "PHP script test with rich push"; $notification['ios'] = $iosspecific; $platform = array(); array_push($platform, "ios"); array_push($platform, "android"); //comment out if you don't want Android $richpush = array(); $richpush['title'] = "Title of rich push"; $richpush['body'] = "Body of rich push"; $push = array("audience"=>"all", "notification"=>$notification, "device_types"=>$platform, "message"=>$richpush); $json = json_encode($push); echo $json; //show the payload $session = curl_init(PUSHURL); curl_setopt($session, CURLOPT_USERPWD, APPKEY . ':' . PUSHSECRET); curl_setopt($session, CURLOPT_POST, True); curl_setopt($session, CURLOPT_POSTFIELDS, $json); curl_setopt($session, CURLOPT_HEADER, False); curl_setopt($session, CURLOPT_RETURNTRANSFER, True); curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type:application/json', 'Accept: application/vnd.urbanairship+json; version=3;')); $content = curl_exec($session); echo $content; //show the response text // Check if any error occured $response = curl_getinfo($session); if($response['http_code'] != 202) { echo "Got negative response from server, http code: ". $response['http_code'] . "\n"; } else { echo "Wow, it worked!\n"; } curl_close($session); ?><?php
Output for 5.4.0 - 5.6.2
Parse error: syntax error, unexpected end of file in /in/DirYL on line 45
Process exited with code 255.
Output for 5.2.0 - 5.3.29
{"audience":"all","notification":{"alert":"PHP script test with rich push","ios":{"badge":"+1","sound":"cat.caf"}},"device_types":["ios","android"],"message":{"title":"Title of rich push","body":"Body of rich push"}} Fatal error: Call to undefined function curl_init() in /in/DirYL on line 24
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Call to undefined function json_encode() in /in/DirYL on line 21
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: json_encode() in /in/DirYL on line 21
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: json_encode() in /in/DirYL on line 21
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: json_encode() in /in/DirYL on line 21