Summary of PHP Development

Source: Internet
Author: User
1.mysql gets the ID of the newly generated AutoNumber

$id =mysql_insert_id (); Get the ID you just inserted

2.php how to tell if the network is connected

$url = "http://www.163.com/test.html";
$file = @fopen ($url, "R");
if (! $file) {
echo "";
Exit
}
?>

3. Determine the day of the week for any date

$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. "
";; Get the English name of the day of the week
echo $wday. "
";
?>

4.mysql querying case-sensitive solutions

Today suddenly found a query statement execution, incredibly case-sensitive

Example: SELECT * FROM table where abc= ' bits ' if abc= ' bits ' will not find the result

So the Internet query, unfortunately can not find the results, only said that in Windows MySQL does not distinguish between the field case, but there are many tell you how to set the size of the method.

Depressed ~

So, I changed a table, found that this table is not case-sensitive, I think the problem is in the string encoding, checked, the normal table field is gbk_chinese_ci, the field of error is Gbk_bin

The answer was found.

5.php-javascript "Back to previous" no cache issues

A lot of friends who write scripts in PHP will encounter such problems, such as a registration page (do not use any Ajax), need to fill in the Account password information, fill out the need to the server to verify, if the verification does not pass, it is necessary to let users re-fill the information, which for many users this is a great torment, It is possible to waive the registration. In general, there are several solutions to this problem:

1. Still call just the page, output the error prompt, and putThe value in value is changed to the value just entered by the user. This should be the best method, but the disadvantage is to be on this pageThe value of the processing, the more troublesome.

2. There are a lot of lazy people like me, encounter validation does not pass, directly output an error prompt page, and add JavaScript code to the page:

Return

Or

Return
This code is returned to the previous page of the code, after the return, in addition to the password type of all the data will remain in the Web page, this is more friendly.

But there are many friends to respond to the use of JS return, the page does not have the data cache, and sometimes there are, really unpredictable. A few days ago I also encountered this problem in the development of the internet Google for a long time, had to start from their own code analysis. At this time, a sentence of session_start (); Caught my attention. Session_Start (); Is the function that opens $_session session, after opening session, it seems that every time you visit a webpage to recall the page. After I removed the sentence, the problem was solved. If you encounter Web page data can not be cached, may wish to remove the session test

6. Calculate the first day of the month on which the current date is located and the date of the last day

PHP calculates the date of the first and last day of the week on which the current date is located.
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 calculates the date of the first and last day of the month on which the current date is located.
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]; Month
echo $ok [1];//Month

7. PHP Cannot delete cookie solution

When the cookie was deleted yesterday in logout.php, it was found that the cookie could not be cleared

To register a cookie, use the following code:

Setcookie ("iwho", "San Liang", 0, "/", "" ");

According to the standard exit code on the manual: Setcookie ("iwho", "", Time ()-3600);//Set the expiration time to one hour ago

But found at all unable to work, turned to the previous PHP4 book, opened the check with Setcookie ("iwho") directly deleted, it is effective, but found that the program again login but unable to register cookies,

It seems that PHP4 is not compatible with PHP5 at all. Try this code today:

Setcookie ("iwho", "", Time ()-3600, "/", "");

It works, everything is fine, it seems, should be in accordance with the format of the registration (the Cookie must be used and set the same parameters can be deleted.) ), indicating the path of the cookie to be deleted

8. How do I get HTML code for a Web page in PHP?

$url = "http://www.myukt.com/index.php";
$html =implode ("\ n", file ($url));
Echo $html;
?>

9. Take the whole function ceil,floor,round,intval

PHP is often used to take the whole function, mainly: Ceil,floor,round,intval

Ceil--into a method to take the whole
Description
float ceil (float value)
Returns the next integer not less than value, in which value is entered if there is a fractional part. The type returned by Ceil () is still float, because the range of float values is usually larger than the integer.

Example 1. Ceil () example

echo ceil (4.3); 5
echo ceil (9.999); 10
?>


Floor--The Rounding method
Description
Float floor (float value)
Returns the next integer not less than value, rounding out the fractional part of value. The type returned by floor () is still float, because the range of float values is usually larger than the integer.

Example 1. Floor () example

echo floor (4.3); 4
echo Floor (9.999); 9
?>


Round--Rounding a floating-point number
Description
Float round (float val [, int precision])
Returns the result of rounding Val based on the specified precision precision (number of digits after decimal point). Precision can also be negative or 0 (the default value).

Example 1. Round () example

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---to integer patterns of variables

Example Intval ()

echo intval (4.3); 4

Echo intval (4.6); 4

?>

10.php using Imagecreatefromjpeg () color lost very badly

Use Imagecreatefromjpeg (), change the size of the output, the color loss is very bad!
and Imagecreatefromgif () and Imagecreatefrompng () are fine.

  • 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.