❮ Tham chiếu chuỗi PHP Show
Thí dụTìm vị trí của lần xuất hiện đầu tiên của "PHP" bên trong chuỗi: echo strpos("I love php, I love php too!","php"); Hãy tự mình thử » Định nghĩa và cách sử dụngHàm strpos () tìm thấy vị trí của lần xuất hiện đầu tiên của một chuỗi bên trong chuỗi khác. Lưu ý: Hàm strpos () nhạy cảm trường hợp. The strpos() function is case-sensitive. Lưu ý: Hàm này an toàn cho nhị phân. This function is binary-safe. Các chức năng liên quan:
Cú phápstrpos (chuỗi, tìm, bắt đầu) Giá trị tham số
Chi tiết kỹ thuật
❮ Tham chiếu chuỗi PHP
Tùy chọn - Tìm ký tự cuối cùng của chuỗi - cả B và C - Tìm kiếm ký tự trong một chuỗi - Vị trí vị trí của ký tự đầu tiên của chuỗi Câu trả lời đúng: Tìm kiếm ký tự trong chuỗi
Tùy chọn - Tìm ký tự cuối cùng của chuỗi - cả B và C - Tìm kiếm ký tự trong một chuỗi - Vị trí vị trí của ký tự đầu tiên của chuỗi
Trong bài viết này, chúng ta sẽ thấy cách tìm vị trí của lần xuất hiện đầu tiên của chuỗi trong một chuỗi khác bằng các hàm strpos () và stripos () trong PHP, và sẽ thấy việc triển khai của chúng thông qua các ví dụ. Cả hai hàm strpos () và stripos () trong PHP đều an toàn nhị phân, điều đó có nghĩa là hàm sẽ xử lý đầu vào của nó dưới dạng luồng byte thô và coi thường mọi nội dung văn bản mà nó có thể chứa. Ở đây, chức năng sẽ hoạt động chính xác trong khi truyền dữ liệu nhị phân tùy ý, tức là.binary-safe which means the function will handle its input as a raw byte stream and disregard every textual content it may contain. Here, the function will work correctly while passing arbitrary binary data ie., a string having non-ASCII bytes &/or null-bytes. Chức năng strpos (): Hàm này giúp chúng tôi tìm thấy vị trí xuất hiện đầu tiên của chuỗi trong chuỗi khác. Điều này trả về một giá trị số nguyên của vị trí của lần xuất hiện đầu tiên của chuỗi. Chức năng này nhạy cảm trường hợp, có nghĩa là nó xử lý các ký tự trường hợp trên và trường hợp thấp hơn khác nhau.This function helps us to find the position of the first occurrence of a string in another string. This returns an integer value of the position of the first occurrence of the string. This function is case-sensitive, which means that it treats upper-case and lower-case characters differently. Syntax: strpos(original_str, search_str, start_pos); Giá trị tham số: & nbsp; Trong số ba tham số được chỉ định trong cú pháp, hai là bắt buộc và một là tùy chọn. Ba tham số được mô tả dưới đây:: Out of the three parameters specified in the syntax, two are mandatory and one is optional. The three parameters are described below:
Loại trả về: Hàm này trả về một giá trị số nguyên đại diện cho chỉ mục của bản gốc_str nơi lần đầu tiên search_str xảy ra.: This function returns an integer value that represents the index of original_str where the string search_str first occurs. Ví dụ: & nbsp; Ví dụ này minh họa hàm strpos () chỉ định vị trí xuất hiện của một chuỗi trong một chuỗi khác.This example illustrates the strpos() function that specifies the position of the occurrence of a string in another string. PHP
Found at position 110 Found at position 111
Found at position 113 Found at position 114 Found at position 115 Found at position 116 Found at position 117 Found at position 118 Found at position 110____9 $search stripos(original_str, search_str, start_pos);2 Found at position 114 stripos(original_str, search_str, start_pos);4 Found at position 118 stripos(original_str, search_str, start_pos);6 Found at position 118 Found at position 115 stripos(original_str, search_str, start_pos);9 Found at position 114 Found at position 113 Found at position 112 Found at position 113 Found at position 114 Found at position 115 Found at position 115 Found at position 117 Found at position 114 Found at position 119 Found at position 114 <?php 1Found at position 114 Found at position 113 Found at position 112 Found at position 113 <?php 6Found at position 117 Found at position 114 Found at position 119
Found at position 119
Found at position 110 Found at position 116 55Found at position 117
Found at position 116 function 0Found at position 117
Found at position 110 function 8
Output: Found at position 11 Chức năng Stripos (): Hàm này cũng giúp chúng tôi tìm thấy vị trí xuất hiện đầu tiên của chuỗi trong chuỗi khác. Điều này trả về một giá trị số nguyên của vị trí của lần xuất hiện đầu tiên của chuỗi. Chức năng này không nhạy cảm trường hợp, có nghĩa là nó đối xử với cả hai trường hợp trên và trường hợp phụ thuộc như nhau. Hàm này hoạt động tương tự như strpos (), sự khác biệt là trường hợp có trường hợp nhạy cảm trong khi strpos () là trường hợp nhạy cảm.This function also helps us to find the position of the first occurrence of a string in another string. This returns an integer value of the position of the first occurrence of the string. This function is case-insensitive, which means it treats both upper-case and lower-case characters equally. This function works similarly as strpos(), the difference is that it is case in-sensitive whereas strpos() is case sensitive. Syntax: stripos(original_str, search_str, start_pos); Giá trị tham số: & nbsp; Trong số ba tham số được chỉ định trong cú pháp, hai là bắt buộc và một là tùy chọn.: Out of the three parameters specified in the syntax, two are mandatory and one is optional.
Loại trả về: Hàm này trả về một giá trị số nguyên đại diện cho chỉ mục của bản gốc_str nơi lần đầu tiên search_str xảy ra.: This function returns an integer value that represents the index of original_str where the string search_str first occurs. Ví dụ: & nbsp; Ví dụ này minh họa hàm stripos () chỉ định vị trí xuất hiện của một chuỗi trong một chuỗi khác.This example illustrates the stripos() function that specifies the position of the occurrence of a string in another string. PHP
Found at position 110 Found at position 111
Found at position 113 Found at position 114 Found at position 115 Found at position 116 $search 3Found at position 118 Found at position 110____9 $search stripos(original_str, search_str, start_pos);2 Found at position 114 stripos(original_str, search_str, start_pos);4 Found at position 118 Found at position 115 , 3Found at position 114 Found at position 113 Found at position 112 Found at position 113 , 8 Found at position 115 Found at position 115 Found at position 117 Found at position 114 Found at position 119 Found at position 114 <?php 1Found at position 114 Found at position 113 Found at position 112 Found at position 113 <?php 6Found at position 117 Found at position 114 Found at position 119
Found at position 119
Found at position 110 Found at position 116 55Found at position 117
Found at position 116 function 0Found at position 117
Found at position 110 function 8
Output: Found at position 11 Chức năng Stripos (): Hàm này cũng giúp chúng tôi tìm thấy vị trí xuất hiện đầu tiên của chuỗi trong chuỗi khác. Điều này trả về một giá trị số nguyên của vị trí của lần xuất hiện đầu tiên của chuỗi. Chức năng này không nhạy cảm trường hợp, có nghĩa là nó đối xử với cả hai trường hợp trên và trường hợp phụ thuộc như nhau. Hàm này hoạt động tương tự như strpos (), sự khác biệt là trường hợp có trường hợp nhạy cảm trong khi strpos () là trường hợp nhạy cảm.
Việc sử dụng hàm strpos trong PHP là gì?Hàm strpos () tìm thấy vị trí của lần xuất hiện đầu tiên của một chuỗi bên trong chuỗi khác.finds the position of the first occurrence of a string inside another string.
Việc sử dụng hàm strlen () và strpos () là gì?Chức năng strpos (): Hàm này giúp chúng tôi tìm thấy vị trí xuất hiện đầu tiên của chuỗi trong chuỗi khác.Điều này trả về một giá trị số nguyên của vị trí của lần xuất hiện đầu tiên của chuỗi.
Điều nào sau đây là việc sử dụng hàm strlen () trong PHP?Strlen () là một hàm tích hợp trong PHP trả về độ dài của một chuỗi đã cho.Nó lấy một chuỗi làm tham số và trả về độ dài của nó.Nó tính toán độ dài của chuỗi bao gồm tất cả các khoảng trắng và các ký tự đặc biệt.returns the length of a given string. It takes a string as a parameter and returns its length. It calculates the length of the string including all the whitespaces and special characters.
Cách chính xác để tạo chức năng trong PHP là gì?Để khai báo một loại cho trả về hàm, thêm một dấu hai chấm (:) và loại ngay trước khung xoăn mở ({) khi khai báo hàm.add a colon ( : ) and the type right before the opening curly ( { )bracket when declaring the function. |