This file contains hidden or 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 cleanInput($input) { | |
| $search = array( | |
| '@<script[^>]*?>.*?</script>@si', // Strip out javascript | |
| '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags | |
| '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly | |
| '@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments | |
| ); | |
| $output = preg_replace($search, '', $input); | |
| return $output; | |
| } |
This file contains hidden or 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 getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) { | |
| $theta = $longitude1 - $longitude2; | |
| $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta))); | |
| $miles = acos($miles); | |
| $miles = rad2deg($miles); | |
| $miles = $miles * 60 * 1.1515; | |
| $feet = $miles * 5280; | |
| $yards = $feet / 3; | |
| $kilometers = $miles * 1.609344; | |
| $meters = $kilometers * 1000; |
This file contains hidden or 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 getTweets($hash_tag) { | |
| $url = 'http://search.twitter.com/search.atom?q='.urlencode($hash_tag) ; | |
| echo "<p>Connecting to <strong>$url</strong> ...</p>"; | |
| $ch = curl_init($url); | |
| curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
| $xml = curl_exec ($ch); | |
| curl_close ($ch); | |
| //If you want to see the response from Twitter, uncomment this next part out: |
This file contains hidden or 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
| // Our custom error handler | |
| function nettuts_error_handler($number, $message, $file, $line, $vars){ | |
| $email = " | |
| <p>An error ($number) occurred on line | |
| <strong>$line</strong> and in the <strong>file: $file.</strong> | |
| <p> $message </p>"; | |
| $email .= "<pre>" . print_r($vars, 1) . "</pre>"; | |
| $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; |
This file contains hidden or 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
| $expected=array('username','age','city','street'); | |
| foreach($expected as $key){ | |
| if(!empty($_POST[$key])){ | |
| ${key}=$_POST[$key]; | |
| } | |
| else{ | |
| ${key}=NULL; | |
| } | |
| } |
This file contains hidden or 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 downloadFromRemote($imageUrl = '', $saveFilePath) { | |
| $image = file_get_contents($imageUrl); | |
| return file_put_contents($saveFilePath, $image); //save the image on local server | |
| } |
This file contains hidden or 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 data_uri($file, $mime) { | |
| $contents=file_get_contents($file); | |
| $base64=base64_encode($contents); | |
| return "data:$mime;base64,$base64"; | |
| } |
This file contains hidden or 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_client_language($availableLanguages, $default='en'){ | |
| if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { | |
| $langs=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']); | |
| foreach ($langs as $value){ | |
| $choice=substr($value,0,2); | |
| if(in_array($choice, $availableLanguages)){ | |
| return $choice; | |
| } | |
| } | |
| } |
This file contains hidden or 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 ordinal($cdnl){ | |
| $test_c = abs($cdnl) % 10; | |
| $ext = ((abs($cdnl) %100 < 21 && abs($cdnl) %100 > 4) ? 'th' | |
| : (($test_c < 4) ? ($test_c < 3) ? ($test_c < 2) ? ($test_c < 1) | |
| ? 'th' : 'st' : 'nd' : 'rd' : 'th')); | |
| return $cdnl.$ext; | |
| } |
This file contains hidden or 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 detect_city($ip) { | |
| $default = 'UNKNOWN'; | |
| if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost') | |
| $ip = '8.8.8.8'; | |
| $curlopt_useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)'; | |
| $url = 'http://ipinfodb.com/ip_locator.php?ip=' . urlencode($ip); |
OlderNewer