Sample code sharing for implementing some small things in PHP

黄舟
Release: 2023-03-07 06:46:01
Original
1448 people have browsed it

1,PHPRead sql server varchar field data, the select result is incomplete

Mssql_query() reads varchar type by default and only takes 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)";
Copy after login

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")) ;
Copy after login

3. PHP time displays am and pm. Modify phpini

Modify php.ini, find;mssql.datetimeconvert = On, remove the previous points No., change on to off, restart apache or iis

4, pop-up box

Copy after login

5, copy directory

$filecount=0; $dircount=0; function copydir($dirFrom,$dirTO) { global $filecount; global $dircount; if(is_file($dirTO)) { die("目标不是目录,无法创建目录 $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 "共拷贝".$filecount."文件,共拷贝目录".$dircount."个";
Copy after login

6, calculate program execution time

Copy after login

7. Determine whether the date format is correct


        
Copy after login

8.DeleteDirectory

 $file删除成功
"; }else{ echo "文件 $file删除失败
"; } } } } } closedir($handle); if(rmdir($pathName)) { $dircount++; echo "目录 $pathName删除成功
"; }else{ echo "目录 $pathName删除失败
"; } } } deleteDir($file); echo "共删除".$filecount."文件,共删除目录".$dircount."个"; ?>
Copy after login

9. Submission cannot be empty

Copy after login

10.jsAutomatically jump to the specified page after n seconds

 自动n秒后跳转到指定页面儿 2011-08-12 16:44:00  
Copy after login

11, Calendar

'; $html .= ''; $html .= '上个月'; $html .= '' . $date['year'] . '-' . $date['mon'] . '    今天'; $html .= '下个月'; $html .= ''; $html .= ''; $html .= '星期日'; $html .= '星期一'; $html .= '星期二'; $html .= '星期三'; $html .= '星期四'; $html .= '星期五'; $html .= '星期六'; $html .= ''; $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+$start['wday'])%7] = $i+1; if ($date_arr[$j][6]) { $j++; } } foreach ($date_arr as $value) { $html .= ''; 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 .= '' . $vvv . '
'.$datemm.''; } else { $html .= '' . $vvv . '
'.$datemm.' '; } } else { $html .= ' '; } } $html .= ''; } $html .= ''; echo $html; ?>
Copy after login

The above is the detailed content of Sample code sharing for implementing some small things in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!