Can anyone tell me how to delete the last character from a string????
I'm new to php and I am trying to compare data from a csv file to the field names. I'm getting the field names in a string seperated by a comma, which means the last character is a ','. When I get the first line from the csv file the fields are seperated by commas but the last field does not have a comma at the end of it. Can anyone help me
hi there!,
as i did, this will help you:
you want to delete comma from last position of string:
do this:
$new_str=substr($str,0,strlen($str)-1);
here $str is your string.
cheers hitesh
Unless you are absoultely positive that the last element is ALWAYS something you want removed, this will work. But, if you want to rest a lil easier, try $str = rtrim($str,","); It only works in later versions of PHP, so check first.
How are you putting your field names to string? Maybe this can be done with implode() which won't put additional ","?
I am new in PHP. Can you please explain how to do. Thanks.