logo

  • Hỏi Đáp
  • Kiến Thức
  • Sức Khỏe
  • Tử Vi
  • Công Nghệ
No Result
View All Result
logo
No Result
View All Result
Trang chủ php

PHP

by Admin _ April 29, 2022

PHP substring is one of the most common PHP string functions. It returns the part of the string. The first argument specifies the string, which will be trimmed.


How to extract characters from a string

To extract a substring from a string in PHP, use the PHP substr() function. The substr() method does not change an original string. If we want lớn extract characters from the end of the string, use a negative start number.

Bạn đang xem: Php

PHP substr

PHP substr() is a built-in string function that returns a part of a string. The substr() method extracts parts of the string, beginning at the character at the specified position, và returns the specified number of characters.


PHP substr() function cuts a part of a string from a string, starting at a specified position. The second argument specifies the position of the trim start. The third argument specifies the length of a string lớn be returned. The start and length arguments can also be negative numbers.

You can grab several characters from a string with a substr() function.

Syntax

The syntax of the PHP String substr() method is the following.


substr(string, start, length)

Arguments

The string parameter is required & specifies the string khổng lồ return a part of.

The start parameter is required, & it is the position where lớn start the extraction. The first character is at index 0.

If the start is non-negative, the returned string will start at the start‘th position in the string, counting from zero. So, for instance, in the string ‘abcdef,’ the character at position 0 is ‘a’, the character at position 2 is ‘c,’ and so forth.

If the start is negative, the returned string will start at the start‘th character from the over of the string.

If the string is less than start characters long, FALSE will be returned. In case of failure or the empty string, False is returned.

Xem thêm: Chỉ Số Cung Hoàng Đạo Gia Đình, Xứng Đáng Gửi Gắm Cả Đời, Top Gia Đình Hoàng Đạo Khiến Vạn

The length parameter is optional, và the number of characters to extract. If you omit the string length, it removes the rest of the string.

Example

See the below example.

See the below output.

*

Use Negative parameters in substr() function

Let’s pass the start as the negative parameter.

See the below output.

*

If an integer is positive, it refers to lớn start from start_position & extract the length from the beginning. If an integer is negative, it refers lớn start from start_position & remove the length from the kết thúc of the string.

If the length parameter is not passed, then the substr() function will return the string starting from the start_position till the end of the string.

For getting the substring of UTF-8 characters, I highly recommend mb_substr. See the following code.

See the output below.

*

Conclusion

PHP substr() is one of the most common PHP string functions. It extracts the characters from the string. The first argument specifies the string that will be trimmed. The second argument specifies the position of the trim start. The third argument specifies the length of the string to be returned. The start và length arguments can also be negative numbers.

Share Tweet Linkedin Pinterest
Previous Post

Hướng dẫn thao tác với database bằng các hàm mysqli

Next Post

Check out all the great

CÙNG CHUYÊN MỤC

form register php

Form register php

09/04/2021
fantastic blog (cms) in php with source code

Fantastic blog (cms) in php with source code

28/04/2021
validate form php javascript

Validate form php javascript

28/04/2021
http diendanlequydon com viewtopic php style 6

Http diendanlequydon com viewtopic php style 6

28/04/2021
hướng dẫn sử dụng chức năng

Hướng dẫn sử dụng chức năng "config php timezone"

24/05/2022
giải mã code php base64

Giải mã code php base64

24/05/2022
tuyển dụng lập trình viên php tại hà nội

Tuyển dụng lập trình viên php tại hà nội

24/05/2022
việc làm wordpress tại đà nẵng

Việc làm wordpress tại đà nẵng

24/05/2022

Newsletter

The most important automotive news and events of the day

We won't spam you. Pinky swear.

Chuyên Mục

  • Hỏi Đáp
  • Kiến Thức
  • Sức Khỏe
  • Tử Vi
  • Công Nghệ

News Post

  • Sửa lỗi vpn

About

Chúng tôi tạo ra trang web nhằm mục đích mang lại kiến thức bổ ích cho cộng đồng, các bài viết được sưu tầm từ nhiều nguồn trên internet giúp mang lại kiến thức khách quan dành cho bạn

©2022 darkedeneurope.com - Website WordPress vì mục đích cộng đồng

Liên Hệ - Giới Thiệu - Nội Quy - Bảo Mật

No Result
View All Result
  • Trang chủ
  • Chuyên mục
    • Hỏi Đáp
    • Kiến Thức
    • Sức Khỏe
    • Tử Vi
    • Công Nghệ
  • Lưu trữ
  • Liên hệ

© 2022 darkedeneurope.com - Website WordPress vì mục đích cộng đồng.