If you are using slack I am sure you have thought of making certain items post real-time to slack so you can keep track of it.. this is actually easier then you think. You can put the below code in a function of use it directly. Lets get started:

define('SLACK_WEBHOOK', 'https://hooks.slack.com/services/*your slack detail*');
$fields = array();
$slackMessage = array();
// Pass through an array of data consisting of a title and a value. This will be added to the clack message
foreach($data as $key => $d) {
	if(is_array($d)){
             $fields[] = array(
			'title' => $key,
			'value' => implode(',',$d),
			'short' => false
		);
	} else {
		$fields[] = array(
			'title' => $key,
			'value' => $d,
			'short' => false
		);
	}
}

$slackData = array(
	'color' => "#f49600",
	'pretext' => '* Insert your message heading *',
	'fields' => $fields,
	'ts' => strtotime(date('Y-m-d'))
);

$slackMessage['attachments'][] = $slackData;

// Make your message
$message = array('payload' => json_encode($slackMessage));

// Use curl to send your message
$c = curl_init(SLACK_WEBHOOK);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $message);
$result = curl_exec($c);
curl_close($c);

Published by Janes Oosthuizen

Programmer and Tech Junky from Bloemfontein, South-Africa. I have been programming for 8 years in various languages including ( CSS, HTML, jQuery, PHP, MySQL, Wordpress and many other ).