How to delete the first few characters from a php string

藏色散人
Release: 2023-03-01 07:10:02
Original
6180 people have browsed it

How to delete the first few characters from a php string

How to delete the first few characters from a php string

The example is as follows:

Yes Use the substr function to return a substring starting from the 5th character:

$str = "The quick brown fox jumps over the lazy dog."
$str2 = substr($str, 4); // "quick brown fox jumps over the lazy dog."
Copy after login

substr definition and usage

## The #substr() function returns a portion of a string.

Note: If the start parameter is negative and length is less than or equal to start, length is 0.

Syntax

substr(string,start,length)
Copy after login
Parameters

string Required. Specifies a part of the string to be returned.

start Required. Specifies where in the string to begin.

Positive number - starts at the specified position in the string

Negative number - starts at the specified position from the end of the string

0 - at the first character in the string Start at

length Optional. Specifies the length of the string to be returned. The default is until the end of the string.

Positive number - Returns from the position of the start parameter

Negative number - Returns from the end of the string

Return value: Returns the extracted part of the string, returns FALSE if it fails , or return an empty string.

Recommended: "

PHP Video Tutorial"

The above is the detailed content of How to delete the first few characters from a php string. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!