PHP - remove charaters from the end of a string.

Posted on 2011-03-25
Last Modified: 2012-05-11
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.
Question by:sabecs
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

dimaj earned 250 total points
ID: 35220642

Here's what you can do:

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

Expert Comment

ID: 35220645

Sorry, it should be -3, not -2. We're stripping off ,') and then appending )
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 35220663
Or str_replace.
$str = str_replace(",')", ")", "AND profile.countryLive LIKE ('4','7','5','42','205',')");

Open in new window


Author Closing Comment

ID: 35220676

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Use Select Query to Return Results as a Form 9 41
php error 27 55
Pull Variable from URL  Use php template 1 32
Find RGB colors from a screen. 2 16
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question