- Forums
- PHP
- Learn How To Remove Letters From End Of String PHP With Substr() Function
This Page Contains information about Learn How To Remove Letters From End Of String PHP With Substr() Function By wallpaperama in category PHP with 12 Replies. [1018], Last Updated: Sat May 18, 2024
wallpaperama
Thu Apr 12, 2007
12 Comments
20090 Visits
if you want to know how you can remove characters from the end of a string in php you can do it with the substr() funcion. lets say we have a string that its equal to "Free Wallpapers At Walpaperama Website"
so lets say i want to remove the last four letters (or characters) from my string so this is how i would get those letters out.
CODE:
<?php
$string = "Free Wallpapers At Walpaperama Website";
$newstring = substr($string, 0, -4);
echo $newstring;
?>
the output will look like this:
CODE:
Free Wallpapers At Walpaperama Web
Note that the number -4 means how many character back you are going to be removing on the string. that's it, we are finish with this small simple tutorial step by step guide. hope you learned something new today about how to do programming in php to be able to get out the last letters or numbers from a sentence or a string in your scripts code this way you can do your own script to show or display the results on your own website.
substr() is avaliable on PHP 4 and PHP 5
substr — Return part of a string
Description: string substr ( string $string, int $start [, int $length] )
substr() returns the portion of string specified by the start and length parameters.
If start is non-negative, the returned string will start at the start'th position in string, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth.
if you want to learn more about the substr() function you can visist php.net
I just want to remove last result comma, I mean I want result like this.
'name', 'name2', 'name3'
Possible ?
Please reply me at seabreezetravels - at - Google