09 Oct remove last character from string in php Posted by Matt | 29 Comments
I tried trim but did not work. Thnx

29 Replies to "remove last character from string in php"

pradeep November 7, 2008 at 4:43 pm | Reply

0

<?php
$str='pradeep';
$len=strlen($str);
$test=substr($str,0,($len-1));
echo $test;
?>
Umendra February 17, 2009 at 8:25 am | Reply

0

i am searching for , i had took values from many checkboxes and while putting them in one coloum of database it takes comma at start as well as end i need to remove both plz suggest
March 16, 2009 at 1:12 am | Reply

0

pab July 28, 2009 at 8:26 am | Reply

0

what if you only want to remove the last two characters but they are numbers, trying to figure that one out
Mike S August 16, 2009 at 1:07 am | Reply

0

Please provide a simple before and after data set, what you currently have and what you want it to look like.
stein August 28, 2009 at 9:52 pm | Reply

0

If you want to remove the 2 first numbers, you can write:
$dag = substr_replace($barcodehex1,"","",+2);
marc-andre menard October 7, 2009 at 2:52 pm | Reply

0

The right way to do that :
substr($returnvalue,0,-1);
0 = start from first caracter
-1 = lenght minus one caracter

voila !
Mel November 25, 2009 at 5:35 am | Reply

0

Am I missing something? When you fwrite to a file you need a 0a to separate string variables. When you fgets your string variable back into your program, the 0a is retained at the end of your string variable!! Is there any way around this? (other than the above.)

Thanks for the above, 'tho!
shemeermali January 29, 2010 at 12:02 pm | Reply

0

Nice, Thanks
john February 1, 2010 at 11:26 am | Reply

0

substr($var, strlen($var)-2, 2);


Please be polite and helpful and do not spam or offend others. We promise you will be treated the same way.

Log in your free account or if you still haven't joined our Webmaster Community Reward Program, you can create your free account now.

Posting tip:
if you use code in your comments please put it in these tags [php], [sql], [css], [js]
PHP code example: [php] echo date("Y-m-d"); [/php]

Thank you,
~ PHPJabbers team ~