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
Solved

PHP - remove charaters from the end of a string.

Posted on 2011-03-25
4
274 Views
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.
0
Comment
Question by:sabecs
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
dimaj earned 250 total points
ID: 35220642
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
 
LVL 7

Expert Comment

by:dimaj
ID: 35220645
Ooops!

Sorry, it should be -3, not -2. We're stripping off ,') and then appending )
0
 
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

0
 

Author Closing Comment

by:sabecs
ID: 35220676
Thanks.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google Maps API and PHP 25 49
Undefined Variable: loop_limit, Undefined Variable: number 3 17
Link failure 16 32
check mysql insert 12 26
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

856 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