How to neglect last character of given string in php?

by barkkathulla 2013-09-26 20:13:42

The following 3 ways are easy to remove substring....


Method 1

$string = "Peacock is a beautiful bird...";

// substr function
echo "substr: " . substr($string, 0, -1);


// mb_substr multibyte version
echo "mb_substr: " . mb_substr($string, 0, -1);





Method 2

$string = "Peacock is a beautiful bird...";

// substr_replace function
echo "substr_replace: " . substr_replace($string ,"",-1);



Method 3

$string = "This is test string..";

// rtrim function
echo "rtrim: " . rtrim($string, ".");

949
like
0
dislike
0
mail
flag

You must LOGIN to add comments