复制代码
function 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 );return trim( $str );>}echo words_limit($yourstring, 50,'...'); orecho words_limit($yourstring, 50);
复制代码
function video_image($url){ $image_url = parse_url($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]; }}>
复制代码
function age_from_dob($dob){$dob = strtotime($dob);$y = date('y', $dob); if (($m = (date('m') - date('m', $dob))) $y++; } elseif ($m == 0 && date('d') - date('d', $dob) $y++; }return date('y') - $y;}echo age_from_dob('2005/04/19'); date in yyyy/mm/dd format.
复制代码
//设置 cookiesetcookie(name, 'value', time()+3600*60*30);//显示 cookieif ($_cookie[name]!=){$_session['name'] = $_cookie[name];}
复制代码
//方法1echo substr(md5(uniqid()), 0, 8); //方法2function 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(asia/calcutta);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]),date($date1[1]),date($date1[2]), date($date1[3]),date($date1[4]),date($date1[5])); $endtime = mktime(date($date2[0]),date($date2[1]),date($date2[2]), date($date2[3]),date($date2[4]),date($date2[5])); $seconds_dif = $starttime-$endtime; return $seconds_dif;}
复制代码
function seconds2days($mysec) { $mysec = (int)$mysec; if ( $mysec === 0 ) { return '0 second'; } $mins = 0; $hours = 0; $days = 0; if ( $mysec >= 60 ) { $mins = (int)($mysec / 60); $mysec = $mysec % 60; } if ( $mins >= 60 ) { $hours = (int)($mins / 60); $mins = $mins % 60; } if ( $hours >= 24 ) { $days = (int)($hours / 24); $hours = $hours % 60; } $output = ''; if ($days){ $output .= $days. days ; } if ($hours) { $output .= $hours. hours ; } if ( $mins ) { $output .= $mins. minutes ; } if ( $mysec ) { $output .= $mysec. seconds ; } $output = rtrim($output); return $output;}
复制代码
复制代码