Home > Backend Development > PHP Problem > How to remove the first character on the right in php

How to remove the first character on the right in php

青灯夜游
Release: 2023-03-15 13:34:02
Original
2624 people have browsed it

php method to remove the first character on the right: 1. Use the rtrim() function to remove the specified character on the right side of the string, the syntax is "rtrim (string, specified character)"; 2. Use substr() and strlen() functions, the syntax is "substr(string,0,strlen(string)-1)".

How to remove the first character on the right in php

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

How to remove the right side of php The first character

#1. Use the rtrim() function

The rtrim() function can remove the specified characters on the right side of the string.

<?php
$str = "Hello World!";
echo $str . "<br>";
echo rtrim($str,"!");
?>
Copy after login

How to remove the first character on the right in php

2. Use the substr() and strlen() functions

The substr() function can start from the specified position of the string Intercept a certain length of characters. The intercepted characters can be called "substring" or "substring",

<?php
$str = "Hello World~";
echo $str . "<br>";
echo substr($str,0,strlen($str)-1);
?>
Copy after login

How to remove the first character on the right in php

Recommended learning: "PHP Video tutorial

The above is the detailed content of How to remove the first character on the right 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