Simple PHP Functions

Source: Internet
Author: User
Tags php book shuffle

Introduction: This is a detailed page for PHP simple functions. It introduces the related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 343926 'rolling = 'no'>

Simple PHP Functions

Topic: simple PHP Functions

Brief Introduction: PHP is simple and clear function syntax

Target Audience: Open SourceCommunityInterested, interested in PHP, a little time to understand PHP

Note: I hope you can still give bricks.

1. Related to MySQL

Mysql_connect

 

Establish a connection with the MySQL server

Syntax

Resource mysql_connect (string server [, string usingname [, string password [,
Bool new_link [, int client_flags])

Eg:

$ Db_host = "localhost ";

$ Db_login = "root ";

$ Db_password = "123456 ";

$ Conn = mysql_connect ($ db_host, $ db_login, $ db_password );

Mysql_data_seek

 

Move the internal query pointer to the query row

Syntax

Bool mysql_data_seek (resource result_indetifier, int row_number)

Eg:

$ Db_host = "localhost ";

$ Db_login = "root ";

$ Db_password = "123456 ";

$ Db_name = "flag ";

$ Conn = mysql_connect ($ db_host, $ db_login, $ db_password );

Mysql_select_db ($ db_name );

$ Res = mysql_query ("select * from product ");

$ ROW = mysql_fetch_array ($ res );

For ($ I = 0; $ I <$ num; $ I ++)

$ ROW = mysql_fetch_array ($ res );

Mysql_data_seek ($ res, 0); // move the pointer back to the first row of the query result

Mysql_fetch_array

 

Store the query results in an array (one record for each array element)

Syntax

Array mysql_fetch_array (resource result [, int result_type])

Eg

$ Db_host = "localhost ";

$ Db_login = "root ";

$ Db_password = "123456 ";

$ Db_name = "flag ";

$ Conn = mysql_connect ($ db_host, $ db_login, $ db_password );

Mysql_select_db ($ db_name );

$ Res = mysql_query ("select * from product ");

$ ROW = mysql_fetch_array ($ res );

Mysql_fetch_object

 

A row of query results is obtained and stored as an object. The usage of mysql_fetch_array () is the same. The difference is that mysql_fetch_object () can only obtain query results by field name.

Echo $ row-> fieldname; // correct usage

Echo $ row-> 0; // incorrect usage

Syntax

Object mysql_fetch_object (resource result)

Eg

$ Db_host = "localhost ";

$ Db_login = "root ";

$ Db_password = "123456 ";

$ Db_name = "flag ";

$ Conn = mysql_connect ($ db_host, $ db_login, $ db_password );

Mysql_select_db ($ db_name );

$ Res = mysql_query ("select * from product ");

$ ROW = $ mysql_fetch_object ($ res );

While ($ row)

{
Echo $ row à P _ id;
Echo $ row à P _ name;

}

Mysql_insert_id

After adding a message using the INSERT command, you can use this function to obtain the unique ID of the newly added record.

Syntax

Int mysql_insert_id ([esource link_identifier])

Eg

$ Db_host = "localhost ";

$ Db_login = "root ";

$ Db_password = "123456 ";

$ Db_name = "flag ";

$ Conn = mysql_connect ($ db_host, $ db_login, $ db_password );

Mysql_select_db ($ db_name );

$ Sqlstr "insert into produce (p_id, p_name) values ('', 'php Book ')";

$ Res = mysql_query ($ res );

$ P_id = mysql_insert_id ();

Mysql_num_rows

There are several rows in the query result.

Syntax

Int mysql_num_rows (resource result)

Eg

$ Db_host = "localhost ";

$ Db_login = "root ";

$ Db_password = "123456 ";

$ Db_name = "flag ";

$ Conn = mysql_connect ($ db_host, $ db_login, $ db_password );

Mysql_select_db ($ db_name );

$ Res = mysql_query ("select * from product ");

$ Num = mysql_num_rows ($ res );

Mysql_query

Send a query statement of SQL syntax

Syntax

Resource mysql_query (string Query [, resource link_identifier])

Eg

$ Db_host = "localhost ";

$ Db_login = "root ";

$ Db_password = "123456 ";

$ Db_name = "flag ";

$ Conn = mysql_connect ($ db_host, $ db_login, $ db_password );

Mysql_select_db ($ db_name );

$ Res = mysql_query ("select * from product ");

Mysql_select_db

Select the name of the database to be accessed

Syntax

Bool mysql_select_db (string database_name [, resource link_identifier])

Eg

$ Db_host = "localhost ";

$ Db_login = "root ";

$ Db_password = "123456 ";

$ Db_name = "flag ";

$ Conn = mysql_connect ($ db_host, $ db_login, $ db_password );

Mysql_select_db ($ db_name );

2. File System Functions

Copy

Copy text

Syntax

Bool copy (string source, string DEST)

Eg

Copy(“abc.txt ","/tmp/newabc.txt ");

Fclose

Close a pointer to open a file

Syntax

Bool fclose (resource handle)

Eg

$Fpw.fopen(“abc.txt "," W ");

Fclose ($ FP );

Fgets

Retrieve the column content from the position indicated by the file pointer

Syntax

String fgets (resource handle [, int length])

Eg

$Fpw.fopen(“abc.txt "," W ");

$ Txtdata = fgets ($ FP, 4096 );

File

Read the entire file content to the array

Syntax

Array file (string filename [, int use_include_path [, resource context])

Eg

$Content1_file(“abc.txt ");

File_exists

Check whether the file exists

Syntax

Bool file_exists (string filename)

Eg

If (file_exists(“abc.txt "))
Echo "this file exists ";

Else

Echo "this file does not exist ";

Filesize

Get File Size

Syntax

Int filesize (string filename)

Eg

Inclusizeinclufilesize(“abc.txt ");

Fopen

Open a file or URL

Syntax

Resource fopen (string filename, string mode [, bool use-include_path [, Resource
Zcontext])

Eg

$Fp=fopen(“abc.txt ");

$ Fp = fopen ("http://www.cnblogs.com/bacteroid/#,”r ");

Fputs

Write data to a file

Syntax

Int fputs (resource handle, string [, int length])

Eg

$Fp=fopen(“abc.txt ");

Fputs ($ FP, "helloworld !");

Fseek

Set the position indicated by the file pointer

Syntax

Int fseek (resource handle, int offset [, int whence])

Eg

$Fpw.fopen(“abc.txt "," W ");

$ Txtdata = fgets ($ FP, 4096 );

Fseek ($ FP, 0); // point the pointer back to the starting position

Mkdir

Create a directory

Syntax

Bool mkdir (string pathname [, int mode [, bool recursive [, Resource
Context])

Eg

Mkdir ("ljt/newfolder ");

Unlink

Delete an object

Syntax

Int unlink (string filename );

Eg

Unlink(cmdabc.txt ");

 

3. Date and Time Functions

Data

Returns the local time/date in the specified format.

Syntax

String date (string format [, int timestamp])

Eg

$ Time = date ("Y-m-d G: I: S ");

Getdate

Obtain date and time information

Syntax

Array getdata ([int timestamp])

Eg

$ Now = getdate ();

$ Year = $ now ["year"];

$ Month = $ now ["month"];

Gettimeofday

Obtain the current time (including Greenwich Mean Time)

Syntax

Array gettimeofday (void)

Eg

$ Time = gettimeofday ();

 

4. string processing functions

Explode

Splits a string into an Array Based on the specified delimiter.

Syntax

Array explode (string separator, string [, int limit])

Eg

$ STR = "A, B, C ";

$ Res = explode (",", $ Str); // $ res [0] =

Implode

Concatenates the array content into a string

Syntax

String implode (string glue, array pieces)

Eg

$ Newarray = array ('A', 'B', 'C ');

$ Res = implode (",", $ newarray); // $ res = a, B, c

Strlen

Returns the length of a string.

Syntax

Int strlen (string)

Eg

Strlen ("www.gxnu.edu.cn"); // returns 15

Substr

Obtains a specified part of the character string (sub-string)

Syntax

String substr ("www.gxnu.edu.cn",); // return "ww. gxnu"

5. mathematical function library

Ceil

Unconditionally carry the decimal part of the Floating Point Number

Syntax

Float Ceil (float value)

Eg

Echo Ceil (9.99); // returns 10

Echo Ceil (9.12); // returns 10

Cos

Returns the cosine of a floating point value.

Syntax

Float cos (float Arg)

Eg

$ Numcos = cos (0.5 );

Floor

Remove the decimal part of the floating point number unconditionally.

Syntax

Float floor (floor value)

Eg

Echo floor (9.12); // return 9

Echo floor (9.99); // return 9

Rand

Generates a random value in a range.

Syntax

Int rand ([int min, in Max])

Eg

$ Num = rand (0,100); // generates a random value between 1 and 100.

Round

Rounds the decimal part of a floating point number to carry.

Syntax

Float round (float value)

Eg

Float round (9.99) // returns 10

Float round (9.12) // return 9

Sin

Returns the sine of a floating point value.

Syntax

Float sin (float Arg)

Eg

$ Numsin = sin (0.5 );

6. SessionFunction

Session_register

Description: variables in one or more sessions

Syntax

Bool session_register (mixed name [, mixed...])

Eg

$ Name = "flag ";

Session_register ("name ");

Session_start

Initialize session information

Syntax

Bool SESSION (void)

Eg

Session_start ();

7,Array Functions

Count

There are several array functions in the calculation array.

Syntax

Int count (mixed var [, int mode])

Eg

Count ($ array );

List

Assign the element values in the array to the variable.

Syntax

Void list (mixed varname, mixed ...)

Eg

$ Array = array (A, B, C );

List ($ str1, $ str2, $ str3) = $ array; // $ str1 =

Range

Creates an array within the specified range.

Syntax

Array range (INT low, int high [, int step])

Eg

$ Array = array (0, 9 );

Shuffle

Re-random sorting of elements in the array

Syntax

Bool shuffle (array)

Eg

Shuffle ($ array );

Author: bacteroid

Source: http://www.cnblogs.com/bacteroid/

The copyright of this article is shared by the author and the blog. You are welcome to repost this article, but you must keep this statement without the author's consent and Article The original text connection is clearly displayed on the page. Otherwise, the legal liability is retained.

Love J2EE follow Java Michael Jackson video station JSON online tools

http://biancheng.dnbcw.info/php/343926.html pageno: 5

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.