Home > Backend Development > PHP Problem > How to remove the first two characters of a string in php

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

青灯夜游
Release: 2023-03-15 08:04:01
Original
3081 people have browsed it

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

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

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php removes strings The first two characters

1. Use the substr() function

The substr() function can intercept a certain length of characters from the specified position of the string. Character, returns the extracted part of the string, returns FALSE on failure, or returns an empty string.

<?php 
$str = "hello,world";
$str2 = substr($str, 2); 
echo $str2;
?>
Copy after login

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

2. Use the substr_replace() function

substr_replace() function to replace part of a string with another string .

<?php 
$str = "world";
$str2 = substr_replace($str, &#39;&#39;, 0,2); 
echo $str2;
?>
Copy after login

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

Recommended learning: "PHP Video Tutorial"

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

Related labels:
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