Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove all specific characters at the end of a string in PHP?

Tags:

string

regex

php

How do I remove the last character only if it's a period?

$string = "something here."; $output = 'something here'; 
like image 478
ggggggggg Avatar asked Jan 13 '10 01:01

ggggggggg


People also ask

How do you remove all characters from a string after a specific character in PHP?

The substr() and strpos() function is used to remove portion of string after certain character. strpos() function: This function is used to find the first occurrence position of a string inside another string. Function returns an integer value of position of first occurrence of string.

How can I remove last 3 characters from a string in PHP?

To remove the last three characters from a string, we can use the substr() function by passing the start and length as arguments.

How do I remove the last 3 characters from a string?

To remove the last three characters from the string you can use string. Substring(Int32, Int32) and give it the starting index 0 and end index three less than the string length. It will get the substring before last three characters.


1 Answers

$output = rtrim($string, '.'); 

(Reference: rtrim on PHP.net)

like image 55
Alix Axel Avatar answered Oct 09 '22 09:10

Alix Axel