Tag Archives: PHP

PHP: Get URL Content Using PHP Curl

/* gets the data from a URL */ function get_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); curl_close($ch); return $data; } Source: http://davidwalsh.name/download-urls-content-php-curl

Posted in Languages | Tagged , | Leave a comment

PHP: How To Convert UTC to Local Time

How to convert your MySQL timestamps from UTC to local time: $gmdatetime = gmdate(“Y-m-d H:i:s”); print “gmdatetime: $gmdatetime\n”; list($gmdate, $gmtime) = explode(‘ ‘, $gmdatetime); list($gmyear, $gmmon, $gmday) = explode(‘-’, $gmdate); list($gmhour, $gmmin, $gmsec) = explode(‘:’, $gmtime); print “gmmktime($gmhour, $gmmin, $gmsec, … Continue reading

Posted in Languages | Tagged , , , | Leave a comment

PHP: How To Get A Time Difference in Human Readable Format

A simple function to return the time since a given timestamp in the past. function time_since($timestamp) { // Init $hash = array(); $now = time(); // Breakdown the time diff $diff = $now – $timestamp; $hash['day'] = floor($diff / 86400); … Continue reading

Tagged , , , | 1 Comment