Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP - remove charaters from the end of a string.

Posted on 2011-03-25
4
Medium Priority
?
280 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
[X]
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
4 Comments
 
LVL 7

Accepted Solution

by:
dimaj earned 1000 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 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 1000 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

636 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