php开发总结
1.mysql取得新生成自动编号的ID
$id=mysql_insert_id(); //取得刚插入的ID
2.php 如何判断网络是否连通
$url = "http://www.163.com/test.html";
$file=@fopen($url,"r");
if (!$file){
echo "";
exit;
}
?>
3.判断任意日期是星期几
$date="2009-03-22";
$datearr=explode("-",$date);
$year=$datearr[0];
$month=sprintf('%02d',$datearr[1]);
$day=sprintf('%02d',$datearr[2]);
$hour=$minute=$second=0;
$dayofweek=getdate(mktime($hour,$minute,$second,$month,$day,$year));
$weekday=$dayofweek['weekday'];
$wday=$dayofweek['wday'];
echo $weekday."
";; //得到星期几的英文名称
echo $wday."
";
?>
4.mysql 查询区分大小写的解决方案
今天突然发现一条查询语句执行时,居然区分大小写
如:select * from 表 where abc='BITS' 如果 abc='bits' 就查不出结果
于是上网查询,可惜查不到结果,只说在windows下mysql不区别字段大小写, 倒是有很多告诉你如何去设置区分大小的方法.
郁闷~
于是,我换了一张表,发现这张表不区分大小写, 我想问题出在字串编码上,查了一下,正常的这个表的字段是gbk_chinese_ci,出错的字段是gbk_bin
答案找到了
5.PHP-Javascript“返回上一页”无缓存问题
很多用PHP写脚本的朋友都会遇到这样的问题,比如一个注册页面(不使用任何AJAX),需要填写账号密码等信息,填写完后需要到服务端验证,如果验证不通过,就要让用户重新填写资料,这对很多用户来说这是一大煎熬,有可能就因此放弃了注册。遇到这种问题,一般有这几种解决方法:
1.仍然调用刚才的页面,输出错误提示,并把中 value的值改为刚才用户输入的值。这应该是最好的方法,但缺点是要在这个页面的的VALUE进行处理,比较麻烦。
2.还有很多懒人像我一样,遇到验证不通过,直接输出一个出错提示页面,并在页面中加入JavaScript的代码:
或
返回
这个代码是返回上一页的代码,返回后,除了密码类型的所有数据均会保留在网页中,这算是比较友好了。
但有很多朋友反应使用JS的返回后,网页上并没有数据的缓存,有时候却又有,真让人捉摸不定。前几天我在开发的时候也碰到了这个问题,上网Google许久未果,只好又从自己的代码分析入手。这时候,一句session_start(); 引起了我的注意。session_start(); 是开启 $_SESSION 会话的函数,开启SESSION后,似乎是每次访问一个网页都要重新调用一次网页。我把这句话去掉以后,问题就解决了。如果遇到网页数据不能缓存的,不妨去掉SESSION试试
6.计算当前日期所在月的第一天,最后一天的日期
php计算当前日期所在周的第一天,最后一天的日期.
function w_fl($i_date)
{
$w_last=date("Y-m-d",strtotime("Sunday",strtotime($i_date)));
return array(
date("Y-m-d",strtotime("-6 days",strtotime($w_last))),
$w_last
);
}
php计算当前日期所在月的第一天,最后一天的日期.
function m_fl($i_date){
$m_first=date("Y-m-01",strtotime($i_date));
return array($m_first,date("Y-m-d",strtotime("+1 month -1day",strtotime($m_first))));
}
$ok=m_fl(date('Y-m-d'));
echo $ok[0]; //月初
echo $ok[1];//月末
7. php无法删除cookie的解决方案
昨天在作logout.php的cookie删除时,发现怎么也无法清除cookie
注册cookie时用以下代码:
setcookie("iwho","耿良",0,"/","");
按照手册上的标准退出代码为: setcookie("iwho", "", time() - 3600);// 将过期时间设为一小时前
但发现根本无法起作用,翻到以前的php4的书,打开查了用 setcookie("iwho") 直接删除,倒是起效果了,但是发现程序再登陆却无法注册cookie了,
看来php4根本无法与php5兼容.今天试了一下这个代码:
setcookie("iwho", "", time() - 3600,"/","");
起效,一切正常了,看来,应该按照注册时的格式(Cookie 必须用和设定时的同样的参数才能删除。),注明要删除的cookie路径
8.如何用php取得一个网页的html代码?
$url="http://www.myukt.com/index.php";
$html=implode("\n",file($url));
echo $html;
?>
9.取整函数ceil,floor,round,intval
经常用到的PHP取整函数,主要是:ceil,floor,round,intval
ceil -- 进一法取整
说明
float ceil ( float value )
返回不小于 value 的下一个整数,value 如果有小数部分则进一位。ceil() 返回的类型仍然是 float,因为 float 值的范围通常比 integer 要大。
例子 1. ceil() 例子
echo ceil(4.3); // 5
echo ceil(9.999); // 10
?>
floor -- 舍去法取整
说明
float floor ( float value )
返回不大于 value 的下一个整数,将 value 的小数部分舍去取整。floor() 返回的类型仍然是 float,因为 float 值的范围通常比 integer 要大。
例子 1. floor() 例子
echo floor(4.3); // 4
echo floor(9.999); // 9
?>
round -- 对浮点数进行四舍五入
说明
float round ( float val [, int precision] )
返回将 val 根据指定精度 precision(十进制小数点后数字的数目)进行四舍五入的结果。precision 也可以是负数或零(默认值)。
例子 1. round() 例子
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.05
echo round(5.055, 2); // 5.06
?>
intval---对变数转成整数型态
例子intval()
echo intval(4.3); //4
echo intval(4.6); // 4
?>
10.php使用ImageCreateFromJPEG() 颜色丢失的非常厉害
使用ImageCreateFromJPEG() ,改变尺寸输出,颜色丢失的非常厉害!
而ImageCreateFromGIF() 和 ImageCreateFromPNG() 就没事。

Outils d'IA chauds

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool
Images de déshabillage gratuites

Clothoff.io
Dissolvant de vêtements AI

AI Hentai Generator
Générez AI Hentai gratuitement.

Article chaud

Outils chauds

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Laravel simplifie la gestion des données de session temporaires à l'aide de ses méthodes de flash intuitives. Ceci est parfait pour afficher de brefs messages, alertes ou notifications dans votre application. Les données ne persistent que pour la demande ultérieure par défaut: $ demande-

L'extension PHP Client URL (CURL) est un outil puissant pour les développeurs, permettant une interaction transparente avec des serveurs distants et des API REST. En tirant parti de Libcurl, une bibliothèque de transfert de fichiers multi-protocol très respectée, PHP Curl facilite Efficient Execu

Laravel fournit une syntaxe de simulation de réponse HTTP concise, simplifiant les tests d'interaction HTTP. Cette approche réduit considérablement la redondance du code tout en rendant votre simulation de test plus intuitive. L'implémentation de base fournit une variété de raccourcis de type de réponse: Utiliser illuminate \ support \ faades \ http; Http :: faux ([[ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Alipay Php ...

Voulez-vous fournir des solutions instantanées en temps réel aux problèmes les plus pressants de vos clients? Le chat en direct vous permet d'avoir des conversations en temps réel avec les clients et de résoudre leurs problèmes instantanément. Il vous permet de fournir un service plus rapide à votre personnalité

L'article traite de la liaison statique tardive (LSB) dans PHP, introduite dans PHP 5.3, permettant une résolution d'exécution de la méthode statique nécessite un héritage plus flexible. Problème main: LSB vs polymorphisme traditionnel; Applications pratiques de LSB et perfo potentiel

L'article examine l'ajout de fonctionnalités personnalisées aux cadres, en se concentrant sur la compréhension de l'architecture, l'identification des points d'extension et les meilleures pratiques pour l'intégration et le débogage.

L'article traite des fonctionnalités de sécurité essentielles dans les cadres pour se protéger contre les vulnérabilités, notamment la validation des entrées, l'authentification et les mises à jour régulières.
