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
  Forums Index
      » PHP Forums
        » » 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:
Post Tags: learn, how, to, remove, letters, from, end, of, string, php, with, substr, function, free php support, php scripts, php questions, php answers, programming, codes, scripts
This Post Has Been Viewed 3350 Times Since Thu Apr 12, 2007 4:59 pm Posted By hostman with 5 replies
Next Post »» Learn How To Remove Letters From The beginning Of a String in PHP Function
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

Leave Your Comments
* Your Name

  * Your Email Address (Will Not Be Published)

* Your Comments


Add Picture To Comments
Yes No             upload
Receive Replies on my Comments
(An email will be sent to you when someone replies to your comments)

     




Comments and replies About Learn How To Remove Letters From End Of String PHP With Substr() Function






:: 1 :: #26012 - Reply By Dave On Mon Oct 29, 2007 8:35 am
this is really useful, thanks!
:: 2 :: #28065 - Reply By Roel On Sat Nov 17, 2007 10:18 am
that is a clear text about this particular fuction :)
:: 3 :: #43537 - Reply By php beginer On Thu Feb 28, 2008 6:29 pm
Reply Learn How To Remove Letters From End Of String PHP With Substr() Function
thank you for your help on this. i learned alot
:: 4 :: #48026 - Reply By Benjamin On Mon Mar 31, 2008 4:18 pm
can i also search for a string or a character from the end of that string?
:: 5 :: #52310 - Reply By Stu On Thu May 01, 2008 9:01 am
many thanks, just what was need!