<无详细内容>
-
- $host = "localhost";
- $uname = "Database username";
- $pass = "Database Password";
- $database = "database name";
- $connection =mysql_connect ($host, $uname, $pass)
- Or Die ("Database Connection Failed");
- $result =mysql_select_db ($database)
- Or Die ("database cannot is selected");
- ?>
Copy Code
- 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, ' ... ');
- Or
- Echo Words_limit ($yourString, 50);
Copy Code
- 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"];
- }
- }
- "/>
Copy Code
- function Age_from_dob ($DOB) {
- $dob = Strtotime ($DOB);
- $y = date (' y ', $dob);
- if ($m = (date (' m ')-date (' m ', $dob))) < 0) {
- $y + +;
- } elseif ($m = = 0 && date (' d ')-date (' d ', $dob) < 0) {
- $y + +;
- }
- Return date (' Y ')-$y;
- }
- echo age_from_dob (' 2005/04/19 '); Date in YYYY/MM/DD format.
Copy Code
- Set cookies
- Setcookie ("name", ' Value ', Time () +3600*60*30);
- Show cookies
- if ($_cookie["name"]!= "") {
- $_session[' name '] = $_cookie["name"];
- }
Copy Code
- Method 1
- Echo substr (MD5 (UNIQID ()), 0, 8);
- Method 2
- function Rand_password ($length) {
- $chars = ' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz ';
- $chars. = ' 0123456789 ';
- $chars. = '!@#%^&* () _,./<>?;:[]{}\|=+ ';
- $str = ";
- $max = strlen ($chars)-1;
- for ($i =0; $i < $length; $i + +)
- $str. = $chars [rand (0, $max)];
- return $str;
- }
- Echo Rand_password (16);
Copy Code
- Date_default_timezone_set ("Asia/calcutta");
- function Dt_differ ($start, $end) {
- $start = Date ("G:i:s:m:d:y", Strtotime ($start));
- $date 1=explode (":", $start);
- $end = Date ("G:i:s:m:d:y", Strtotime ($end));
- $date 2=explode (":", $end);
- $starttime = mktime (Date ($date 1[0]), date ($date 1[1]), date ($date 1[2]),
- Date ($date 1[3]), date ($date 1[4]), date ($date 1[5]);
- $endtime = mktime (Date ($date 2[0]), date ($date 2[1]), date ($date 2[2]),
- Date ($date 2[3]), date ($date 2[4]), date ($date 2[5]);
- $seconds _dif = $starttime-$endtime;
- return $seconds _dif;
- }
Copy Code
- 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;
- }
Copy Code
- $zip = Zip_open ("Moooredale.zip");
- if ($zip) {
- while ($zip _entry = 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);
- }
- ?>
Copy Code |