Common functions in PHP dynamic web page development-PHP Tutorial

Source: Internet
Author: User
Some common functions in PHP dynamic web page development. Add the following reference content at the beginning of the php web page :? $ Time_startgetmicrotime (); functiongetmicrotime () {list ($ usec, $ sec) explode (, microtime (); return (float adds the following to the beginning of the php web page

Reference content is as follows:
$ Time_start = getmicrotime ();
Function getmicrotime ()
{
List ($ usec, $ sec) = explode ("", microtime ());
Return (float) $ usec + (float) $ sec );
}
?>

Then add the following code to the end.

Reference content is as follows:
$ Time_end = getmicrotime ();
Printf ("[page Execution time: %. 2f millisecond]", ($ time_end-$ time_start) * 1000 );
?>

$ File = fopen ($ filename, r) or die ("Sorry, cannot open: $ filename ");

Or here, it is understood that, because in php, the data type is not distinguished, so $ file can be either int or bool, so such a statement will not report an error. However, some friends may not understand the process.

In most languages, in statements such as bool or bool, if the previous value is true, the latter value will no longer be judged. So if the fopen function is correctly executed, an int value greater than 0 will be returned (this is actually "true"), and subsequent statements will not be executed. If the fopen function fails to be executed, false is returned. then, the system checks whether the following expression is true.

After the die () is executed, the program stops running no matter what is returned, and the specified error message is displayed, thus debugging is achieved.

Php check box

Reference content is as follows:

D. php

Reference content is as follows:
$ Fd = $ _ post [checkbox];
For ($ I = 0; $ I <(sizeof ($ fd); $ I ++ ){
$ Newhpt = $ newhpt. $ fd [$ I]. ",";
}
Echo $ newhpt ."
";
?>

In php code, what does @ in front of a function mean?

@ Is used to ignore the error message generated when the function is called.

Date addition in php

Reference content is as follows:
$ Fd = $ _ post [checkbox];
For ($ I = 0; $ I <(sizeof ($ fd); $ I ++ ){
$ Newhpt = $ newhpt. $ fd [$ I]. ",";
}
Echo $ newhpt ."
";
?>

Php watermarks

Reference content is as follows:
// Read the target file
$ Im = imagecreatefromjpeg ("11000022.16.jpg ");
// Set the mixed mode
Imagealphablending ($ im, true );
// Read the watermark
$ Im2 = imagecreatefrompng ("watermark.png ");
// The following are the words I wrote.
// $ Color = imagecolorallocate ($ im2, 0, 0 );
// Imagestring ($ im2, 12, 1, 1, "I love u jingjing", $ color );
// Word end
// Copy the watermark to the target file
Imagecopy ($ im, $ im2, 5, 5, 0, 0,220, 34 );
// Output, which can be output to a file
Imagejpeg ($ im );
Imagedestroy ($ im );
Imagedestroy ($ im1 );
?>
$ Im = imagecreatefromjpeg ("11000022.16.jpg ");
// $ Im = imagecreatefromgif ("eee.gif ");
// $ Im = imagecreatefrompng ("11000022.16.png ");
$ Black = imagecolorallocate ($ im, 0,140, 76 );
$ Red = imagecolorallocate ($ im, 255, 0, 0 );
$ String = chr (0xe5 ). chr (0xae ). chr (0x89 ). chr (0xe5 ). chr (0xba ). chr (0x86 ). chr (0xe6 ). chr (0x88 ). chr (0xbf ). chr (0xe4 ). chr (0xba ). chr (0xa7 ). chr (0xe7 ). chr (0xbd ). chr (0x91 );
// Imagestring ($ im, 12, 10, 10, $ string, $ red );
Imagettftext ($ im, 20, 0, 4, 30, $ red, "fzdhtjw. ttf", $ string );
Imagepng ($ im );
Imagedestroy ($ im );
?>
// This function can be used in gd after converting Chinese characters to UTF-8!
Function gb2utf8 ($ gb)
{
If (! Trim ($ gb ))
Return $ gb;
$ Filename = "gb2312.txt ";
$ Tmp = file ($ filename );
$ Codetable = array ();
While (list ($ key, $ value) = each ($ tmp ))
$ Codetable [hexdec (substr ($ value,)] = substr ($ value );
$ Utf8 = "";
While ($ gb)
{
If (ord (substr ($ gb, 127)>)
{
$ This = substr ($ gb, 0, 2 );
$ Gb = substr ($ gb, 2, strlen ($ gb ));
$ Utf8. = u2utf8 (hexdec ($ codetable [hexdec (bin2hex ($ this)-0x8080]);
}
Else
{
$ Gb = substr ($ gb, 1, strlen ($ gb ));
$ Utf8. = u2utf8 (substr ($ gb, 0, 1 ));
}
}
$ Ret = "";
For ($ I = 0; $ I $ Ret. = chr (substr ($ utf8, $ I, 3 ));
Return $ ret;
}
Function u2utf8 ($ c)
{
For ($ I = 0; $ I $ Str = "";
If ($ c <0x80 ){
$ Str. = $ c;
}
Else if ($ c <0x800 ){
$ Str. = (0xc0 | $ c> 6 );
$ Str. = (0x80 | $ c & 0x3f );
}
Else if ($ c <0x10000 ){
$ Str. = (0xe0 | $ c> 12 );
$ Str. = (0x80 | $ c> 6 & 0x3f );
$ Str. = (0x80 | $ c & 0x3f );
}
Else if ($ c <0x200000 ){
$ Str. = (0xf0 | $ c> 18 );
$ Str. = (0x80 | $ c> 12 & 0x3f );
$ Str. = (0x80 | $ c> 6 & 0x3f );
$ Str. = (0x80 | $ c & 0x3f );
}
Return $ str;
}
Header ("content-type: image/gif ");
$ Im = imagecreate (400,300 );
$ Bkg = imagecolorallocate ($ im, 0, 0 );
$ Clr = imagecolorallocate ($ im, 255,255,255 );
$ Fnt = "wb. ttf ";
// Include ("gb2utf8. php ");
$ Str = gb2utf8 ("China ");
Imagettftext ($ im, 20, 0, 10, 20, $ clr, $ fnt, $ str );
Imagegif ($ im );
Imagedestroy ($ im );
?>

Reference content is as follows:

// Use javascript and select components in combination
// In the process of writing a program, after selecting the select object option,
// You do not need to submit a button, but directly trigger the action.
// To keep the selected options on the page. Finally
// Use the onchange attribute and
// Value to implement this function.
// The code is as follows (the file name is "test. php "):

Switch ($ mon ){
Case: echo select your Constellation:; break;
Case 1: echo your constellation is Aquarius; break;
&

References :? $ Time_start = getmicrotime (); function getmicrotime () {list ($ usec, $ sec) = explode ("", microtime (); return (float...

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.