Jump to content

removing the last if its a period


freelance84

Recommended Posts

Users are able to add single line comments to a page.

 

If the last character is a full stop I want to be able to remove it.

 

After researching the substr I thought this would work:

if(substr($get_comment_to_add, -1) == ".")
{
	substr_replace($get_comment_to_add ,"",-1);
}

 

I know the "substr" bit in the "if" returns the last character. So I am assuming the =="." is incorrect. I have tried escaping with a backslash but it still didn't work.

 

Any ideas anyone?

 

Also I cannot use str_replace because it is only the last period i want to remove, not any others in between.

Link to comment
https://forums.phpfreaks.com/topic/202768-removing-the-last-if-its-a-period/
Share on other sites

Hi, yea i got it to work with the folloing:

 

if(substr($get_comment_to_add, -1) == ".")
{
	$com_prt1 = substr_replace($get_comment_to_add ,"",-1);
}
else{
	$com_prt1 = $get_comment_to_add;
}

 

This takes out the last character if it's a period and leaves in any others in between

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.