PHP common basic functions __ function

Source: Internet
Author: User
Tags cos mathematical functions natural logarithm sin square root

PHP functions are divided into system functions, user functions

1,php functions are case-insensitive

Function Prototypes:
return type function name (type parameter)

2.1, the common mathematical functions in the system function

ABS (Eumber) to absolute value

Sin (float) sine calculation sin (x)

cos (float) cosine calculation cos (x)

Log (float) natural logarithm computation

sqrt (float) Open square root calculation

LOG10 (float) 10 The logarithm of the base

The secondary value of exp (float) natural logarithm E

Pow (float x,float y) sub-square X's y-square

Pi ()

RAND ([Min],[max]) takes random numbers

2.2 String Functions

Strtolower () string to lowercase

Strtoupper () string to uppercase

Trim () to intercept string and trailing spaces

SUBSTR (string,start,[length]) fetch substring

strlen (String str) Get string length

Strpos (parent string, search character, [offset]) looking for a character in a string to appear first

strcmp (STR1,STR2) string comparison

2.3 File system functions:
int filesize (string filename) to get file size

int feof (int fp) test file pointer point to end of file

int fopen (string filename,string mode) Open file or URL

int fclose (int fp) closes an open file

string fread (int fp,int n) reads file n bytes

String fgets (int fp,int n) Gets the line that the file pointer refers to (for large file processing)

int fwrite (int fp,string string,int[n]) to write to file

int fputs (int fp,string str,int[n]) to write to file

int mkdir (string pathname,int mode) to create a directory

int rmdir (string dirname) Delete directory

int rename (string oldname,string newname) renamed


2.4 Network functions:
int Fsockopen (String hostname,int port,int[errno],string[errstr],int
[Timeout]) Open Network Socket link

String gethostbyname (string hostname) DNS query, returning IP URL

Array Gethostbynamel (string hostname) returns all IP for machine name


2.5 MySQL Database functions:
int mysql_connect (string[hostname][:p ort],string[username],string

[Password]); MySQL Server connection

int mysql_select_db (string database_name,int[link_identifier]); Select a
Database

int mysql_query (string query,int[link_identifier]); Execute SQL string

int mysql_close (Int[link_identifier]); Turn off MySQL server connection

2.6 Custom Functions

Format: Function name (parameter//writable or writable) {

Functional processes and operations to be performed
Return "value returned"; can return not return
}

A function can be nested, that is, a function can call a function (but: call yourself very easily to produce dead follow

Ring

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.