Learn How To Remove Letters From End Of String PHP With Substr() Function
learn how to remove letters from end of string php with substr() function
learn, how, to, remove, letters, from, end, of, string, php, with, substr, function
Learn How To Remove Letters From End Of String PHP With Substr() Function
Post Description: learn how to remove letters from end of string php with substr() function
POST# 390
Posted On: Fri Feb 29, 2008 12:01 pm
web hosting
Topic: Learn How To Remove Letters From End Of String PHP With Substr() Function
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


Mon Oct 29, 2007 8:35 am
1
Dave
Reply #993
this is really useful, thanks!
Sat Nov 17, 2007 10:18 am
2
Roel
Reply #994
that is a clear text about this particular fuction :)
Thu Feb 28, 2008 6:29 pm
3
php beginer
Reply #995
Picture 20080228-43537-zzy1p89tgzw1jwol3bk7p-xicpaiuugwwo7rxpppcml1rnurl6ailtp-2mpq96qej63sd7n
thank you for your help on this. i learned alot

What do you think?

* name:  

* email:  

* Please enter comments:


Receive Replies on my Comments
(An email will be sent to you when someone replies to your comments)

Add image to comments
yes no             upload