Hướng dẫn
Quảng cáo

Hàm strpbrk() trong PHP

Hướng dẫn cách sử dụng hàm strpbrk() trong lập trình PHP

Tác dụng của hàm strpbrk()

The strpbrk() function searches a string for any of a set of characters, in a case-sensitive manner.

The following table summarizes the technical details of this function.

Return Value: Returns the portion of the string starting from the first matched character to the end of the string (including that character), or FALSE if no character is found.
Version: PHP 5+


The basic syntax of the strpbrk() function is given with:

strpbrk(string, charlist);

The following example shows the strpbrk() function in action.

// Sample string
$str = "Rain, rain, go away";

// Searching string
echo strpbrk($str, "row");


The strpbrk() function accepts the following parameters.

Parameter Description
string Required. Specifies the string to search in.
charlist Required. Specifies a string containing the list of characters to search for.

More Examples

Here're some more examples showing how strpbrk() function actually works:

The following example shows the case-sensitive behavior of this function, gives different output than the previous example, because this time charlist contains the uppercase letter "R".

// Sample string
$str = "Rain, rain, go away";

// Searching string
echo strpbrk($str, "Row");

Bài viết này đã giúp ích cho bạn?

Bài viết mới