PHP implementation of some small things sample code share

Source: Internet
Author: User
1, PHP read SQL Server varchar field data, select results are incomplete

Mssql_query () reads the varchar type by default to only 255 bytes of data, if the field exceeds this range, use CONVERT (text, table.comment) to convert the field type to text.

$q = "Select CONVERT (TEXT, USERINFO.INV) as Te from UserInfo where  (1=1)";

2. Time

$shijianchuo = Strtotime ("$logintime"), $past _logintime = Date ("y/m/d", $shijianchuo -24*60*60), $today _time=date (" Y-m-d "), $zh _time = Strtotime (" $today _time "), $yesterday _time= date (" y-m-d ", Strtotime (" 1 day "," $zh _time ")); Tomorrow_time= date ("y-m-d", Strtotime ("+1 Day", "$zh _time"));

3, PHP time display am and PM modify Phpini

Modify php.ini, locate; Mssql.datetimeconvert = ON, remove the preceding semicolon, modify on to off, restart Apache or IIS

4. Popup box

<script language= "javascript" >    function Check (form) {        if (form.txt_user.value== "") {            alert (" Please enter the user name "); Form.txt_user.focus (); return false;               }        if (form.txt_pwd.value== "") {            alert ("Please enter password"); Form.txt_pwd.focus (); return false;        }    } </script>

5. Copy Directory

$filecount =0; $dircount =0;function copydir ($dirFrom, $dirTO) {    global $filecount;    Global $dircount;     if (Is_file ($dirTO))    {die        ("Destination is not a directory, cannot create directory $dirTO");    }     if (!file_exists (Dirto))    {        mkdir ($dirTO);        $dircount + +;    }         $handle =opendir ($dirFrom);         while (($file =readdir ($handle))!==false)    {        if ($file! = "." && $file! = "...")        {            $fileFrom = $dirFrom. Directory_separator. $file;            $fileTo = $dirTO. Directory_separator. $file;                         if (Is_dir ($fileFrom))            {                copydir ($fileFrom, $fileTo);            } else{                Copy ($fileFrom, $fileTo);                $filecount + +            ;    }}} Closedir ($handle); } copydir (Mail,mailbak); echo "Total copy". $filecount. " Files, shared Directories ". $dircount." A ";

6. Calculate Program Execution Time

<?php//the code that gets the current time in a function runtime () {      $times = explode ("", Microtime ());      $nowtime = $times [1]+ $times [0];      return $nowtime;} Suppose this is the beginning of the page $start_time = runtime (); Here's the beginning. Page code//your codes goes here//Suppose this is the top of the page $end_time = Runtime (); $cost _time = $end _time-$start _time; Processing output Execution Time $cost_time = round ($cost _time,4); The execution time of the output page echo "Page Execution time:". $cost _time. " Seconds ";? >

7. Determine if the date format is correct

<?php/*** method: IsDate () * Function: Determine whether the date format is correct * parameter: $str date string $format date format * return: Boolean */function isdate ($str, $format = "y-m-d") {$ Strarr = Explode ("-", $str), if (Empty ($STRARR)) {return false;} foreach ($strArr as $val) {if (strlen ($val) <2) {$val = "0". $val;} $NEWARR []= $val;} $str =implode ("-", $NEWARR);    $unixTime =strtotime ($STR);    $checkDate = Date ($format, $unixTime);    if ($checkDate = = $str)        return true;    else        return false;} Instance if (IsDate ("2010-1-1")) {echo "true";} Else{echo "false";}

8. Delete directory

<?php $filecount =0; $dircount = 0; $file = "Mail";    function Deletedir ($pathName) {global $filecount;     Global $dircount; if (file_exists ($pathName)) {if ($handle =opendir ($pathName)) {while ($file =readdir ($handle))!                    ==false) {if ($file! = "." && $file! = "...")                        {$file = $pathName. Directory_separator. $file;                        if (Is_dir ($file)) {Deletedir ($file); }else{if (unlink ($file)) {$filecou                                nt++;                            echo "File <b> $file </b> Delete Success <br>";                            }else{echo "File <b> $file </b> delete failed <br>"; }}}}} CLosedir ($handle);            if (RmDir ($pathName)) {$dircount + +;        echo "Catalog <b> $pathName </b> Delete Success <br>";        }else{echo "Catalog <b> $pathName </b> Delete failed <br>"; }}}deletedir ($file); echo "Delete all". $filecount. " files, deleting Directories ". $dircount." A ";? >

9. Submission cannot be empty

<input type=text onblur= "if (this.value.length==0) {alert (' cannot be null '); This.focus ();}" >

10, JS automatically n seconds after the jump to the specified page

<js> automatically n seconds after the jump to the specified page 2011-08-12 16:44:00<script type= "Text/javascript" >var time = 10; Time, Seconds function Redirect () {    window.location = "url to skip";} var i = 0;function dis () {    document.all.s.innerhtml = "Still remaining" + (Time-i) + "seconds";    i++;} Timer=setinterval (' Dis () ', 1000); Display time Timer=settimeout (' Redirect () ', duration * 1000); Jump </script>  <span id= "s" ></span>

11. Calendar

<?php/** * Calendar */$time = date (' y-m-d '), if (function_exists (' Date_default_timezone_set ')) {Date_default_timezone_set  (' PRC '); } $date = Isset ($_get[' date ')? $_get[' date ': $time; $date = getdate (Strtotime ($date)); $end = getdate (mktime (0, 0, 0, $date [' mon '] + 1, 1, $date [' Year '])-1); $start = getdate (mktime (0, 0, 0, $date [' mon '], 1, $date [' Year ']); $pre = Date (' y-m-d ', $start [0]-1);  $next = Date (' y-m-d ', $end [0] + 86400); $html = ' <table width= ' 90% "border=" 1 "cellspacing=" 0 "cellpadding=" 0 "align=" center "style=" line-height:250%; Font-family:verdana; font-size:12px; " > '; $html. = ' <tr> '; $html. = ' <td align= ' center ' ><a href= '. $PHP _self. '? date= '. $pre. ' > Last month </a></td> '; $html. = ' <td colspan= "5" align= "Center" > ". $date [' Year ']. '-' . $date [' mon ']. ' <a href=?date= '. Date (' y-m-d '). ' > Today </a></td> '; $html. = ' <td align= ' center ' ><a href= '. $PHP _self. '? date= '. $next. ' > next month </a></Td> '; $html. = ' </tr> '; $html. = ' <tr> '; $html. = ' <td> Sunday </td> '; $html. = ' <td> Monday </td> '; $html. = ' <td> Tuesday </td> '; $html. = ' <td> Wednesday </td> '; $html. = ' <td> Thursday </td> '; $html. = ' <td> Friday </td> '; $html. = ' <td> Saturday </td> '; $html. = ' </tr> '; $arr _tpl = Array (0 = ', 1 = ', 2 = ', 3 = ', 4 = ', 5 = ', 6 = '); $date _arr = Array (); $j = 0; for ($i = 0; $i < $end [' Mday ']; $i + +) {if (!isset ($date _arr[$j]) {$date _arr[$j] = $arr _tpl;} $date _arr[$j] [($i + $sta rt[' Wday '])%7] = $i +1; if ($date _arr[$j][6]) {$j + +;}} foreach ($date _arr as $value) {$html. = ' <tr> '; foreach ($value as $v) {if ($v >9) {$vvv = $v;} else{$VVV = "0". $v;} $datemm = $date [' Year ']. ' -'. $date [' mon ']. '  -'. $VVV; if ($v) {if ($v = = $date [' mday ']) {$html. = ' <td><b> '. $vvv. ' </b><br> '. $datemm. ' </td> '; } else {$html. = ' <td> '. $vvv. ' <br> '. $datemm. ' </td> '; }} else {$html. = ' <td> </td> ';}} $html. = ' </tr> '; } $html. = ' </table> '; echo $html;?>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.