Usage of character search functions strpos, strrchr, and strpbrk in php

Source: Internet
Author: User
This article mainly introduces the usage of character search functions strpos, strrchr, and strpbrk in php, the usage and attention of strpos, strrchr, and strpbrk in php are analyzed in detail in the form of examples.

This article mainly introduces the usage of character search functions strpos, strrchr, and strpbrk in php, the usage and attention of strpos, strrchr, and strpbrk in php are analyzed in detail in the form of examples.

This document describes the usage of strpos, strrchr, and strpbrk in php. Share it with you for your reference. The details are as follows:

① The strpos () function returns the position where the string first appears in another string. If the string is not found, false is returned.

Syntax: strpos (string, find, start). The Code is as follows:

The Code is as follows:

$ Str = "hello world"; // defines string 1
$ Result = strpos ($ str, "ll"); // execute the following command to find the earliest location
Echo $ result; // output result, 2

② The strrchr () function searches for the position of the last occurrence of a string in another string, and returns all characters from this position to the end of the string. If the result fails, false is returned.

Syntax: strrchr (string, char). The Code is as follows:

The Code is as follows:

$ Str = "hello world"; // defines string 1
$ Result = strrchr ($ str, "o"); // run the following command to find the last position.
Echo $ result;

③ The strpbrk () function searches for any of the specified characters in the string. This function returns the remainder of the position at which the specified character first appears. If not found, false is returned.

Syntax: strpbrk (string, charlist). The Code is as follows:

The Code is as follows:

$ Str = "hello world"; // defines string 1
$ Result = strpbrk ($ str, "oe"); // perform the search operation.
Echo $ result; // output result, hello world


Prompt and comment.

Note: This function is case sensitive.

I hope this article will help you with PHP programming.

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.