1、PHP读取sql server varchar字段数据,select结果不完整
Mssql_query()读取varchar 类型时默认只取255字节数据,如果字段超过这个范围,使用CONVERT(TEXT, table.comment),将字段类型转化为TEXT。
$q = "SELECT CONVERT(TEXT, userinfo.inv) as te FROM userinfo where (1=1)";
2、时间
$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时间显示am和pm修改phpini
修改php.ini,找到;mssql.datetimeconvert = On ,去掉前面的分号,修改on为off,重启apache 或iis
4、弹出框
<script language="javascript"> function check(form){ if(form.txt_user.value==""){ alert("请输入用户名");form.txt_user.focus();return false; } if(form.txt_pwd.value==""){ alert("请输入密码");form.txt_pwd.focus();return false; } } </script>
5、复制目录
$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."个";
6、计算程序执行时间
<?php //将获取当前时间的代码放在一个函数里 function runtime(){ $times = explode(" ",microtime()); $nowtime = $times[1]+$times[0]; return $nowtime; } //假设这里是页面开头 $start_time = runtime(); //这里开始是的页面代码 //your code goes here //假设这里是页面顶部 $end_time = runtime(); $cost_time = $end_time - $start_time; //处理输出执行时间 $cost_time = round($cost_time,4); //输出页面的执行时间 echo "页面执行时间为:".$cost_time."秒"; ?>
7、判断日期格式是否正确
<?php /** * 方法:isdate() * 功能:判断日期格式是否正确 * 参数:$str 日期字符串 $format日期格式 * 返回:布尔值 */ 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; } //实例 if(isdate("2010-1-1")){ echo "true"; }else{ echo "false"; }
8、删除目录
<?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)) { $filecount++; echo "文件<b> $file</b>删除成功<br>"; }else{ echo "文件<b> $file</b>删除失败<br>"; } } } } } closedir($handle); if(rmdir($pathName)) { $dircount++; echo "目录<b> $pathName</b>删除成功<br>"; }else{ echo "目录<b> $pathName</b>删除失败<br>"; } } } deleteDir($file); echo "共删除".$filecount."文件,共删除目录".$dircount."个"; ?>
9、提交不能为空
<input type=text onBlur="if (this.value.length==0) {alert('不能为空');this.focus();}">
10、js 自动n秒后跳转到指定页面儿
<js> 自动n秒后跳转到指定页面儿 2011-08-12 16:44:00 <script type="text/javascript"> var time =10; //时间,秒 function Redirect(){ window.location = "要跳去的url"; } var i = 0; function dis(){ document.all.s.innerHTML = "还剩" + (time - i) + "秒"; i++; } timer=setInterval('dis()', 1000); //显示时间 timer=setTimeout('Redirect()',time * 1000); //跳转 </script> <span id="s"></span>
11、日历
<?php /** * 日历 */ $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 . '">上个月</a></td>'; $html .= '<td colspan="5" align="center">' . $date['year'] . '-' . $date['mon'] . ' <a href=?date='.date('Y-m-d').'>今天</a></td>'; $html .= '<td align="center"><a href="' . $PHP_SELF . '?date=' . $next . '">下个月</a></td>'; $html .= '</tr>'; $html .= '<tr>'; $html .= '<td>星期日</td>'; $html .= '<td>星期一</td>'; $html .= '<td>星期二</td>'; $html .= '<td>星期三</td>'; $html .= '<td>星期四</td>'; $html .= '<td>星期五</td>'; $html .= '<td>星期六</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+$start['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; ?>
以上是php实现一些小东西的示例代码分享的详细内容。更多信息请关注PHP中文网其他相关文章!

PHP是一种服务器端脚本语言,用于动态网页开发和服务器端应用程序。1.PHP是一种解释型语言,无需编译,适合快速开发。2.PHP代码嵌入HTML中,易于网页开发。3.PHP处理服务器端逻辑,生成HTML输出,支持用户交互和数据处理。4.PHP可与数据库交互,处理表单提交,执行服务器端任务。

PHP在过去几十年中塑造了网络,并将继续在Web开发中扮演重要角色。1)PHP起源于1994年,因其易用性和与MySQL的无缝集成成为开发者首选。2)其核心功能包括生成动态内容和与数据库的集成,使得网站能够实时更新和个性化展示。3)PHP的广泛应用和生态系统推动了其长期影响,但也面临版本更新和安全性挑战。4)近年来的性能改进,如PHP7的发布,使其能与现代语言竞争。5)未来,PHP需应对容器化、微服务等新挑战,但其灵活性和活跃社区使其具备适应能力。

PHP的核心优势包括易于学习、强大的web开发支持、丰富的库和框架、高性能和可扩展性、跨平台兼容性以及成本效益高。1)易于学习和使用,适合初学者;2)与web服务器集成好,支持多种数据库;3)拥有如Laravel等强大框架;4)通过优化可实现高性能;5)支持多种操作系统;6)开源,降低开发成本。

PHP没有死。1)PHP社区积极解决性能和安全问题,PHP7.x提升了性能。2)PHP适合现代Web开发,广泛用于大型网站。3)PHP易学且服务器表现出色,但类型系统不如静态语言严格。4)PHP在内容管理和电商领域仍重要,生态系统不断进化。5)通过OPcache和APC等优化性能,使用OOP和设计模式提升代码质量。

PHP和Python各有优劣,选择取决于项目需求。1)PHP适合Web开发,易学,社区资源丰富,但语法不够现代,性能和安全性需注意。2)Python适用于数据科学和机器学习,语法简洁,易学,但执行速度和内存管理有瓶颈。

PHP用于构建动态网站,其核心功能包括:1.生成动态内容,通过与数据库对接实时生成网页;2.处理用户交互和表单提交,验证输入并响应操作;3.管理会话和用户认证,提供个性化体验;4.优化性能和遵循最佳实践,提升网站效率和安全性。

PHP在数据库操作和服务器端逻辑处理中使用MySQLi和PDO扩展进行数据库交互,并通过会话管理等功能处理服务器端逻辑。1)使用MySQLi或PDO连接数据库,执行SQL查询。2)通过会话管理等功能处理HTTP请求和用户状态。3)使用事务确保数据库操作的原子性。4)防止SQL注入,使用异常处理和关闭连接来调试。5)通过索引和缓存优化性能,编写可读性高的代码并进行错误处理。

在PHP中使用预处理语句和PDO可以有效防范SQL注入攻击。1)使用PDO连接数据库并设置错误模式。2)通过prepare方法创建预处理语句,使用占位符和execute方法传递数据。3)处理查询结果并确保代码的安全性和性能。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

Dreamweaver CS6
视觉化网页开发工具

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

Dreamweaver Mac版
视觉化网页开发工具