This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_settings() { | |
var doc_location = document.location.href; | |
var url_strip = new RegExp("http:\/\/.*\/"); | |
var base_url = url_strip.exec(doc_location); | |
var settings = { "base_url" : base_url } | |
return settings; | |
} | |
settings = get_settings(); | |
alert(settings.base_url); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//PHP - Get Gmail new messages (unread) from Atom Feed | |
$username = urlencode('my-gmail-account'); | |
$password = 'my-password'; | |
$tag = ''; | |
$handle = curl_init(); | |
$options = array( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$date_a = strtotime('2010-11-25'); | |
$date_b = strtotime('2012-11-25'); | |
if($date_a >= $date_ab{ | |
echo 'date_a >= date_b'; | |
}else{ | |
echo 'date_a < date_b'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function distance($lat1, $lon1, $lat2, $lon2, $unit) { | |
$theta = $lon1 - $lon2; | |
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); | |
$dist = acos($dist); | |
$dist = rad2deg($dist); | |
$miles = $dist * 60 * 1.1515; | |
$unit = strtoupper($unit); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function slug($str){ | |
$str = strtolower(trim($str)); | |
$str = preg_replace('/[^a-z0-9-]/', '-', $str); | |
$str = preg_replace('/-+/', "-", $str); | |
return $str; | |
} | |
echo slug('This is my string ;) '); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$fh = fopen("contacts.csv", "r"); | |
while($line = fgetcsv($fh, 1000, ",")) { | |
echo "Contact: {$line[1]}"; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function extract_emails($str){ | |
$regexp = '/([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+/i'; | |
preg_match_all($regexp, $str, $m); | |
return isset($m[0]) ? $m[0] : array(); | |
} | |
$test_string = 'This is a test string... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$from = new DateTime('0000-00-00 00:00:00'); | |
$to = new DateTime('now'); | |
$interval = $to->diff($from); | |
//2011 years, 4 months, 5 days, 11 hours, 13 minutes, 49 seconds | |
echo $interval->format('%Y years, %m months, %d days, %H hours, %i minutes, %s seconds'); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*********************************************************************************************************************\ | |
* LAST UPDATE | |
* ============ | |
* March 22, 2007 | |
* | |
* | |
* AUTHOR | |
* ============= | |
* Kwaku Otchere |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function contains($str, $content, $ignorecase=true){ | |
if ($ignorecase){ | |
$str = strtolower($str); | |
$content = strtolower($content); | |
} | |
return strpos($content,$str) ? true : false; | |
} |
OlderNewer