Common PHP function formats

Source: Internet
Author: User
========================================================== ====================
Substr
========================================================== ====================
Return part of a string (PHP 3, PHP 4, PHP 5)

String substr (string, int start [, int length])

Substr () returns the portion of string specified by the start and length parameters.

If start is non-negative, the returned string will start at the start 'th position in string, counting from zero. for instance, in the string 'abcdef', the character at position 0 is 'A', the character at position 2 is 'C', and so forth.

========================================================== ====================
Strpos
========================================================== ====================
Find position of first occurrence of a string (PHP 3, PHP 4, PHP 5)

Int strpos (string haystack, mixed needle [, int offset])

Returns the numeric position of the first occurrence of needle in the haystack string. Unlike the strrpos (), this function can take a full string as the needle parameter and the entire string will be used.

If needle is not found, strpos () will return Boolean false.

Warning:
This function may return a Boolean value of false, but may also return a non-Boolean value equivalent to false, such as 0 or "". For more information, see the Boolean section. The = operator should be used to test the return value of this function.

Note:
This function can be safely used for binary objects.

========================================================== ====================
Strpos
========================================================== ====================
Find position of first occurrence of a string (PHP 3, PHP 4, PHP 5)

Int strpos (string haystack, mixed needle [, int offset])

Returns the numeric position of the first occurrence of needle in the haystack string. Unlike the strrpos (), this function can take a full string as the needle parameter and the entire string will be used.

If needle is not found, strpos () will return Boolean false.

Warning:
This function may return a Boolean value of false, but may also return a non-Boolean value equivalent to false, such as 0 or "". For more information, see the Boolean section. The = operator should be used to test the return value of this function.

Note:
This function can be safely used for binary objects.

========================================================== ====================
Explode
========================================================== ====================
Use one string to split another string (PHP 3, PHP 4, PHP 5)

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

Description
This function returns an array composed of strings. Each element is a substring of a string, which is separated by a string separator as a boundary point. If the limit parameter is set, the returned array contains up to limit elements, and the last element contains the rest of the string.

If separator is a null string (""), explode () returns false. If the value of separator cannot be found in string, explode () returns an array containing a single string element.

If the limit parameter is negative, all elements except the last limit element are returned. This feature is added in PHP 5.1.0.

For historical reasons, although implode () can receive two parameter sequences, explode () cannot. You must ensure that the separator parameter is prior to the string parameter.

Note:
The limit parameter is added to PhP 4.0.1.

========================================================== ====================
Isset
========================================================== ====================
Check whether the variable is set (PHP 3, PHP 4, PHP 5)

Bool isset (mixed var [, mixed var [,...])

Description
If var exists, true is returned; otherwise, false is returned.

If unset () is used to release a variable, it will no longer be isset (). If you use isset () to test a variable that is set to null, false is returned. Note that a NULL byte ("0") is not equivalent to the null constant of PHP.

Warning:
Isset () can only be used for variables, because passing any other parameter will cause a parsing error. To check whether a constant has been set, use the defined () function.

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.