Hướng dẫn strpbrk php

[PHP 5, PHP 7, PHP 8]

strpbrkSearch a string for any of a set of characters

Description

strpbrk[string $string, string $characters]: string|false

Parameters

string

The string where characters is looked for.

characters

This parameter is case sensitive.

Return Values

Returns a string starting from the character found, or false if it is not found.

Examples

Example #1 strpbrk[] example

See Also

  • strpos[] - Find the position of the first occurrence of a substring in a string
  • strstr[] - Find the first occurrence of a string
  • preg_match[] - Perform a regular expression match

devnuhl

8 years ago

If you're not looking to duplicate the rest of the string, but instead just want the offset, in the spirit of the str*pos[] functions, use strcspn[]

guillaume dot barranco at free dot fr

4 years ago

A little modification to Evan's code to use an array for the second parameter :

❮ Tham chiếu chuỗi PHP

Thí dụ

Tìm kiếm một chuỗi cho các ký tự "oe" và trả về phần còn lại của chuỗi mà từ đó nó tìm thấy lần xuất hiện đầu tiên của các ký tự được chỉ định:

Định nghĩa và Cách sử dụng

Hàm strpbrk [] tìm kiếm một chuỗi cho bất kỳ ký tự nào được chỉ định.

Lưu ý: Hàm này phân biệt chữ hoa chữ thường.

Hàm này trả về phần còn lại của chuỗi từ nơi nó tìm thấy lần xuất hiện đầu tiên của một ký tự được chỉ định, nếu không, nó trả về FALSE.

Cú pháp

Giá trị tham số

ParameterDescription
string Required. Specifies the string to search
charlist Required. Specifies the characters to find

Chi tiết kỹ thuật

Giá trị trả lại:Phiên bản PHP:
Trả về chuỗi bắt đầu từ ký tự được tìm thấy, nếu không, nó trả về FALSE
5+

Các ví dụ khác

Thí dụ

Hàm này phân biệt chữ hoa chữ thường ["W" và "w" sẽ không xuất ra giống nhau]:

❮ Tham chiếu chuỗi PHP


Chủ Đề