Time of Update: 2016-07-25
function generateCsv($data, $delimiter = ',', $enclosure = '"') { $handle = fopen('php://temp', 'r+'); foreach ($data as $line) { fputcsv($handle, $line, $delimiter, $enclosure); } rewind($handle); while (!feof($handle)) {
Time of Update: 2016-07-25
網站架構方面採用nobackend這種方案 現在的應用開發模式過度重視後端的搭建,而實際上我們早已為簡化後端開發做了很多年的工作,因此兄弟連創始人李超針對現在更注重UX的環境,提出一個不同的解決方案——noBackend,優先PHP培訓前端開發。 就是說 web,ios,android只是個展示層,持久化操作統一丟給api。 先不考慮 模板渲染這一塊,我們可能會把這塊放到前端。 目前糾結就是 web的session 和 app的token
Time of Update: 2016-07-25
使用下面的函數可以擷取任何網域名稱使用者的完整細節 function whois_query($domain) { // fix the domain name: $domain = strtolower(trim($domain)); $domain = preg_replace('/^http:\/\//i', '', $domain); $domain = preg_replace('/^www\./i', '', $domain); $domain =
Time of Update: 2016-07-25
$xml_string=" ben A h2o K "; //load the xml string using simplexml function$xml = simplexml_load_string($xml_string); //loop through the each node of moleculeforeach ($xml->molecule as $record){
Time of Update: 2016-07-25
function imagefromURL($image,$rename){$ch = curl_init($image);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);$rawdata=curl_exec ($ch);curl_close ($ch);$fp = fopen("$rename",'
Time of Update: 2016-07-25
有時候,當在網站填寫表單,使用者可能會輸入錯誤的郵箱地址,這個函數可以驗證郵箱地址是否有效。 function is_validemail($email){$check = 0;if(filter_var($email,FILTER_VALIDATE_EMAIL)){$check = 1;}return $check;}複製代碼 用法: $email = "blog@open.com";$check = is_validemail($email);echo $check;// If the
Time of Update: 2016-07-25
function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) { $theta = $longitude1 - $longitude2; $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) *
Time of Update: 2016-07-25
function getRealIpAddr() { if (!emptyempty($_SERVER['HTTP_CLIENT_IP'])) { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!emptyempty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy {
Time of Update: 2016-07-25
這個程式碼片段可以方便你禁止某些特定的 IP 位址訪問你的網站 if ( !file_exists('blocked_ips.txt') ) { $deny_ips = array( '127.0.0.1', '192.168.1.1', '83.76.27.9', '192.168.1.163' );} else { $deny_ips = file('blocked_ips.txt');}// read user ip adress:$ip =
Time of Update: 2016-07-25
function is_valid_url($url){ $p1 ='/(http|https|ftp):\/\/[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(\/.*)?$/i'; return preg_match($p1, $url);} function is_valid_email($email){ if (filter_var($email, FILTER_VALIDATE_EMAIL)) return true; else return false;}
Time of Update: 2016-07-25
function unzip($location,$newLocation){ if(exec("unzip $location",$arr)){ mkdir($newLocation); for($i = 1;$i $file = trim(preg_replace("~inflating: ~","",$arr[$i])); copy($location.'/'.$file,$newLocation.'/'.$file); unlink($location.'/'.$file); }
Time of Update: 2016-07-25
$date1 = date( 'Y-m-d' );$date2 = "2015-12-04";$diff = abs(strtotime($date2) - strtotime($date1));$years = floor($diff / (365*60*60*24));$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));$days = floor(($diff - $years * 365*60*60*24 - $
Time of Update: 2016-07-25
/** desc:採集網頁中的郵箱的代碼 */ $url='http://www.xxx.net'; //要採集的網址 $content=file_get_contents($url); //echo $content; function getEmail($str) { //$pattern =
Time of Update: 2016-07-25
function unzip($location,$newLocation){ if(exec("unzip $location",$arr)){ mkdir($newLocation); for($i = 1;$i $file = trim(preg_replace("~inflating: ~","",$arr[$i])); copy($location.'/'.$file,
Time of Update: 2016-07-25
以下是對PHP計算2點經緯度之間的距離代碼進行了分析介紹 function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) { $theta = $longitude1 - $longitude2; $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(
Time of Update: 2016-07-25
使用下面的 PHP 程式碼片段可以在一個目錄中列出所有檔案和檔案夾 function list_files($dir){ if(is_dir($dir)) { if($handle = opendir($dir)) { while(($file = readdir($handle)) !== false) { if($file != "." && $file !=
Time of Update: 2016-07-25
使用下面的 PHP 程式碼片段可以檢測使用者瀏覽器所使用的語言 function get_client_language($availableLanguages, $default='en'){ if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $langs=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']); foreach ($langs as $value){
Time of Update: 2016-07-25
之前我們提供了如何使用 Mandrill 發送郵件的 PHP 程式碼片段,但是如果你不想使用第三方服務,那麼可以使用下面的 PHP 程式碼片段。 function send_mail($to,$subject,$body){$headers = "From: KOONK\r\n";$headers .= "Reply-To: blog@koonk.com\r\n";$headers .= "Return-Path: blog@koonk.com\r\n";$headers .=
Time of Update: 2016-07-25
header("content-type:image/jpeg"); /*一、簡單的映像輸出*/ $im = imagecreate(60,40); $pink = imagecolorallocate($im,35, 25,220);imagejpeg($im); //imagestring($im,16, 200, 200,"I LOVE YOU",); /* 二、將字串寫入到圖片中 */ //載入圖片 $me=imagecreatefromjpeg("..
Time of Update: 2016-07-25
function dominant_color($image){$i = imagecreatefromjpeg($image);for ($x=0;$x for ($y=0;$y $rgb = imagecolorat($i,$x,$y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> & 0xFF; $b = $rgb & 0xFF; $rTotal += $r;