- $host="localhost";
- $uname="資料庫使用者名稱";
- $pass="資料庫密碼" ;
- $database = "資料庫名稱";
- $connection=mysql_connect($host,$uname,$pass)
- or die("資料庫連線失敗");
-
- $result =mysql_select_db($database)
- or die("無法選擇資料庫");
-
- ?>
複製程式碼
- 函數words_limit( $str, $num, $append_str='' ){
- $words = preg_split( '/[s] /', $str, -1, PREG_SPLIT_OFFSET_CAPTURE );
- if( isset($words[$num][1]) ){
- $str = substr( $str, 0, $words[$num][1] ).$append_str;
- }
- unset( $words, $num );
- 返回修剪( $str );>
- }
-
- echo Words_limit($yourString, 50,'...' ) ;
-
- 或
-
- echo Words_limit($yourString, 50);
複製程式碼
- function video_image($url){
- $image_url = parse_url($url);
- if($image_url['host'] == '$url);
- if($image_url['host'] == 'www.youtube. com' ||
- $image_url['host'] == 'youtube.com'){
- $array =explode("&", $image_url['query']);
- return "http ://img.youtube.com/vi/".substr($array[0], 2)."/0.jpg";
- }else if($image_url['host'] == 'www. youtu.be' ||
- $image_url['host'] == 'youtu.be'){
- $array =explode("/", $image_url['path']);
- return "http://img.youtube.com/vi/".$array[1]."/0.jpg";
- }else if($image_url['host'] == 'www.vimeo.com ' ||
- $image_url['host'] == 'vimeo.com'){
- $hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/".
- substr($image_url['path'], 1).".php"));
- return $hash[0]["thumbnail_medium"];
- }
- }
-
複製程式碼
-
- 函數age_from_dob($dob){
- $dob = strtotime($dob);
- $y = date('Y', $dob);
- if (($m = (date('m') - date('m', $dob))) $y ;
- } elseif ($m == 0 && date( ' d') - 日期('d', $dob) $y ;
- }
- 回傳日期('Y') - $y;
- }
-
回顯age_from_dob('2005/04/19'); yyyy/mm/dd 格式的日期。
複製程式碼
-
- //設定Cookie
- setcookie("name", 'value', time() 3600*60*30);
-
- //顯示Cookie
- if ($_COOKIE["name"]!=""){
- $_SESSION['name'] = $_COOKIE["name"];
}
複製代碼
-
- //方法1
- echo substr(md5(uniqid()), 0, 8);
-
- //方法2
- function rand_password( $length){
- $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
- $chars .= '0123456789' ;
- $chars .= '! :[]{}|= ';
-
- $str = '';
- $max = strlen($chars) - 1;
-
- for ($i=0; $i $str .= $chars[rand(0, $max)];
-
- return $str;
- }
-
echo rand_password(16 );
複製程式碼
-
- date_default_timezone_set("亞洲/加爾各答");
-
- function dt_differ($start, $end){
- $start = date("G:i: s:m:d:Y", strtotime($start));
- $date1=explode(":", $start);
-
- $end = date("G:i:s: m:d:Y", strtotime($end));
- $date2=explode(":", $end);
-
- $starttime = mktime(date($date1[0]),日期($date1[1]),日期($date1[2]),
- 日期($date1[3]),日期($date1[4]),日期($date1[5]));
- $endtime = mktime(日期($date2[0]),日期($date2[1]),日期($date2[2]),
- 日期($date2[3]),日期($date2 [4]),date($date2[5]));
-
- $seconds_dif = $starttime-$endtime;
-
- return $seconds_dif;
}
複製程式碼
- function secondary2days($mysec) {
- $mysec = (int)$mysec;
- if ( $mysec === 0 ) {
- return '0第二';
- }
-
- $分鐘= 0;
- $小時= 0;
- $天= 0;
-
-
- if ( $mysec >= 60 ) {
- $mins = (int)($mysec / 60);
- $mysec = $mysec % 60;
- }
- if ( $mins >= 60 ) {
- $
- if ( $mins >= 60 ) {
- $
- $ hours = (int)($mins / 60);
- $mins = $mins % 60;
- }
- if ( $hours >= 24 ) {
- $days = (int) ($小時/ 24);
- $小時= $小時% 60;
- }
-
- $output = '';
-
- if ($days){
- $輸出. = $days." 天";
- }
- if ($hours) {
- $output .= $hours." 小時";
- }
- if ( $mins ) {
- $output .= $mins." 分鐘";
- }
- if ( $mysec ) {
- $output .= $mysec." 秒";
- }
$output = rtrim ($output); return $output; }
複製
-
-
-
$zip = zip_open("moooredale.zip");
- if ($zip) {
- while ($zip_entry = zip_readry = zip_read zip)) {
- $fp = fopen(zip_entry_name($zip_entry), "w");
- if (zip_entry_open($zip, $zip_entry, "r")) {
- $buf = zip_entry_read ( $zip_entry, zip_entry_filesize($zip_entry));
- fwrite($fp,"$buf");
- zip_entry_close($zip_entry);
- fclose($fp);
- zip_close($zip);
- }
- ?>
複製程式碼
|