PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ssand
Forum Commoner
Posts: 72 Joined: Sat Jun 22, 2002 9:25 pm
Location: Iowa
Post
by ssand » Sun Feb 26, 2006 11:26 pm
I am using
It doesn't seem to work. Do I need to use a different function for commas?
Thanks.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Feb 26, 2006 11:28 pm
that should be fine. Maybe your $value has extra "invisible" data in it?
Code: Select all
var_export(htmlentities($value,ENT_QUOTES));may be of use..
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Sun Feb 26, 2006 11:34 pm
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sun Feb 26, 2006 11:36 pm
because it was assumed he wants to only strip the commas from the beginning and end of the string
ssand
Forum Commoner
Posts: 72 Joined: Sat Jun 22, 2002 9:25 pm
Location: Iowa
Post
by ssand » Sun Feb 26, 2006 11:37 pm
Well it returns
So I have
Code: Select all
var_export(htmlentities($value,ENT_QUOTES));
$value = trim($value, ",");
......
Then inserts to a database and it is setting $value as 69 ?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Feb 26, 2006 11:45 pm
and you want it to return what from that example? 69192? Trim only removes the given characters from the
edges of a string, not the inside. For that,
str_replace() is often the best option.
ssand
Forum Commoner
Posts: 72 Joined: Sat Jun 22, 2002 9:25 pm
Location: Iowa
Post
by ssand » Sun Feb 26, 2006 11:51 pm
Thanks, this seems to work.
Code: Select all
$value = str_replace(",", '', $value);
After Jcart's post I realized that was the problem. I
didn't want from the beginning and end, I needed middle!
Edit
feyd wrote: and you want it to return what from that example? 69192? Trim only removes the given characters from the
edges of a string, not the inside. For that,
str_replace() is often the best option.
Yes, I should've posted that a little clearer. I wanted to keep all the numbers. Just remove the comma.
Last edited by
ssand on Sun Feb 26, 2006 11:54 pm, edited 1 time in total.
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Sun Feb 26, 2006 11:54 pm
Glad you got it working!
While we are talking about str_replace. How can I replace multiple things with a character?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Feb 27, 2006 12:08 am
nickman013 wrote: How can I replace multiple things with a character?
explain.
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Mon Feb 27, 2006 12:13 am
Umm the best way to explain it is like this...
for example.
I have this string with this in it "D,$%E->V"
I would like to know how to strip out the , $ % - > so it just displays DEV .
Thanks!
josh
DevNet Master
Posts: 4872 Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida
Post
by josh » Mon Feb 27, 2006 12:21 am
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Mon Feb 27, 2006 12:23 am
Thanks that took out many lines out of my codes. I used str_replaces for each character I wanted out.
Thank You
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Feb 27, 2006 12:23 am
That'd be regex or multiple passes by str_replace. Using array's with str_replace work well in that instance.