Solved

PHP - remove charaters from the end of a string.

Posted on 2011-03-25
4
265 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 82

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
The viewer will learn how to count occurrences of each item in an array.
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now