• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

PHP - remove charaters from the end of a string.

How do I remove the last comma and quote from this string?

AND profile.countryLive LIKE ('4','7','5','42','205',')

so that it becomes

AND profile.countryLive LIKE ('4','7','5','42','205')

Note: The string length will vary.

Thanks in advance for your comments.
0
sabecs
Asked:
sabecs
  • 2
2 Solutions
 
dimajCommented:
http://us.php.net/manual/en/function.substr.php

Here's what you can do:

$rest = substr("AND profile.countryLive LIKE ('4','7','5','42','205',')", 0, -2) . ")";
0
 
dimajCommented:
Ooops!

Sorry, it should be -3, not -2. We're stripping off ,') and then appending )
0
 
Dave BaldwinFixer of ProblemsCommented:
Or str_replace.
$str = str_replace(",')", ")", "AND profile.countryLive LIKE ('4','7','5','42','205',')");

Open in new window

0
 
sabecsAuthor Commented:
Thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now