Home > Backend Development > PHP Tutorial > How to Remove a Period from the End of a String in PHP?

How to Remove a Period from the End of a String in PHP?

Patricia Arquette
Release: 2024-11-10 15:35:03
Original
939 people have browsed it

How to Remove a Period from the End of a String in PHP?

Eliminating Specific Characters from a String's Termination in PHP

In PHP, the efficient removal of specific characters at the end of a string is a common task. One scenario commonly encountered is the selective removal of a period (.) at the end of a string. To address this specific issue, let's explore a solution using PHP's built-in functions.

Using rtrim to Remove a Period

To selectively remove a period at the end of a string, the rtrim() function can be utilized. It takes two parameters: the string to be manipulated and the characters to be trimmed from the right end.

Example:

$string = "something here.";
$output = rtrim($string, '.');

// Result: $output = 'something here'
Copy after login

By invoking rtrim() with the string and '.' as arguments, any trailing periods in the string are eliminated, leaving behind the desired output.

Reference:

For further information on the rtrim() function, please refer to its documentation on PHP.net: https://www.php.net/manual/en/function.rtrim.php

The above is the detailed content of How to Remove a Period from the End of a String in PHP?. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template