Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to remove the first two characters of a string by php

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is a detailed introduction to "how to remove the first two characters of a string in php". The content is detailed, the steps are clear, and the details are properly handled. I hope this article "how to remove the first two characters of a string in php" can help you solve your doubts. Let's go deeper and learn new knowledge together with the ideas of Xiaobian.

php Methods to remove the first two characters of a string: 1. Use the substr() function, syntax "substr($str,2)";2. Use the substr_replace() function, syntax "substr_replace($str,'',0,2)".

Operating environment of this tutorial: Windows 7 system, PHP7.1 version, DELL G3 computer

Php removes the first two characters of a string

Method 1: Use the substr() function

Output:

Description:

The substr() function returns a portion of a string. The syntax is as follows:

substr(string,start,length) Parameter Description string Required. Specifies a string of which part is to be returned. Start is required. Specifies where the string starts.

Positive number-starts at the specified position in the string

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

0 -starts at the first character in the string

Length is optional. Specifies the length of the string to return. The default is until the end of the string.

Positive-returns from where the start parameter is located

Negative number-returns from end of string

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

Method 2: Use the substr_replace() function

substr_replace() function is used to replace the specified position, the specified length of the character, when the replacement value is empty string Yes can be achieved to remove the function of the string.

Description:

The substr_replace() function replaces part of a string with another string. The syntax is as follows:

substr_replace(string,replacement,start,length) Parameters Description string Required. Specify the string to check. Replacement is required. Specifies the string to insert. Start is required. Specifies where the substitution starts in the string.

Positive number-starts at the specified position in the string

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

0 -starts at the first character in the string

Length is optional. Specify how many characters to replace. The default is the same length as the string.

Positive number-length of string being replaced

Negative-Number of characters replaced starting at the end of the string

0 -insert rather than replace

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

Read here, this article "php how to remove the first two characters of the string" article has been introduced, want to master the knowledge points of this article also need to be used by yourself to understand, if you want to know more about the relevant content of the article, welcome to pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report