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() 就没事。

Setting session cookie parameters in PHP can be achieved through the session_set_cookie_params() function. 1) Use this function to set parameters, such as expiration time, path, domain name, security flag, etc.; 2) Call session_start() to make the parameters take effect; 3) Dynamically adjust parameters according to needs, such as user login status; 4) Pay attention to setting secure and httponly flags to improve security.

The main purpose of using sessions in PHP is to maintain the status of the user between different pages. 1) The session is started through the session_start() function, creating a unique session ID and storing it in the user cookie. 2) Session data is saved on the server, allowing data to be passed between different requests, such as login status and shopping cart content.

How to share a session between subdomains? Implemented by setting session cookies for common domain names. 1. Set the domain of the session cookie to .example.com on the server side. 2. Choose the appropriate session storage method, such as memory, database or distributed cache. 3. Pass the session ID through cookies, and the server retrieves and updates the session data based on the ID.

HTTPS significantly improves the security of sessions by encrypting data transmission, preventing man-in-the-middle attacks and providing authentication. 1) Encrypted data transmission: HTTPS uses SSL/TLS protocol to encrypt data to ensure that the data is not stolen or tampered during transmission. 2) Prevent man-in-the-middle attacks: Through the SSL/TLS handshake process, the client verifies the server certificate to ensure the connection legitimacy. 3) Provide authentication: HTTPS ensures that the connection is a legitimate server and protects data integrity and confidentiality.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools