How to remove the first and last string in php

青灯夜游
Release: 2023-03-16 09:52:01
Original
2566 people have browsed it

Removal method: 1. Use the trim() function to delete substrings with the same beginning and end, the syntax is "trim($str,"specified substring")"; 2. Use the ltrim() and rtrim() functions To delete substrings with different beginning and end, the syntax is "ltrim(rtrim($str,"substring at the end"),"substring at the beginning")".

How to remove the first and last string in php

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, DELL G3 computer

php remove the first and last characters String method

#Case 1: Delete strings with the same beginning and end--use trim()

trim() to delete both strings Specified substring on the side

<?php
$str = &#39;abc12345abc&#39;;
echo $str . "<br>";
echo trim($str,"abc");
?>
Copy after login

How to remove the first and last string in php

Case 2: Delete strings with different beginning and end--use ltrim() and rtrim()

  • ltrim() - Removes the specified substring on the left side of the string

  • rtrim() - Removes the specified substring on the right side of the string

<?php
$str = &#39;ABC12345abc&#39;;
echo $str . "<br>";
echo ltrim(rtrim($str,"abc"),"ABC");
?>
Copy after login

How to remove the first and last string in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to remove the first and last 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