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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.