Php character search function _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Character search function in php. The stristr () function is used to locate the first occurrence of a string in another string. If successful, the rest of the string is returned (from the matching point ). If the stristr () function does not find the position where the string first appears in another string.

If successful, the rest of the string is returned (from the matching point ). If this string is not found, false is returned.

Syntax
Stristr (string, search)
*/
$ Str = "hello world"; // define a string
$ Result = stristr ($ str, "w"); // perform the search operation
Echo $ result; // output the search result, which will output "world"

/*

The stripos () function returns the position where the string first appears in another string.

If this string is not found, false is returned.

Syntax
Stripos (string, find, start)

*/

$ Str = "hello world"; // define a string
$ Result = stripos ($ str, "w"); // perform the search operation.
Echo $ result; // output the search result, which is 6

/*
*/
$ Str = "hello world"; // define a string
$ Result = stripos ($ str, "l"); // perform the search operation.
Echo $ result; // output the search result. 2 is returned.

/*
The strspn () function returns the number of specific characters contained in the string.

Syntax
Strspns (string, charlist, start, length)
*/

$ Str = "hello world"; // define a string
$ Result = strspn ($ str, "khlleo"); // search for the length that meets the condition
Echo $ result; // Number of output result lengths. 5 is returned.

/*
*/

$ Str = "hello world! ??? "; // Define a string
Echo $ str ."
"; // Output the original string
Echo convert_cyr_string ($ str, 'W', 'A'); // output the converted string "hello world! ?.? "

The http://www.bkjia.com/PHPjc/631717.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/631717.htmlTechArticlestristr () function looks for the position where the string first appears in another string. If successful, the rest of the string is returned (from the matching point ). If this string is not found...

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.