View Full Version : Creating delimiters...standard solution?

04-02-2007, 03:17 AM
This seems like such a dumb question, but...

When all of you guys have a need for delimited values (let's say for an SQL insert query), how are you doing it?

What I mean is: let's say your delimiter is a comma "," ... a for or foreach loop will always put one comma too many, either at the front or the end.

Of course I'm not STUCK on this problem, but every time I try to solve it, the solution seems horribly ugly, and I just was interested in how everyone else is doing it.

04-02-2007, 03:35 AM
Easy way: Use one of the trim functions (ltrim, trim, rtrim) and list your delimiter in the string charlist parameter.

04-02-2007, 04:14 AM
Yeah...I'm having some trouble with that...

trim($s, ","); doesn't seem to work...

Does everything have to be in ASCII values or something??

04-02-2007, 04:16 AM

I thought the function just automatically changed the string...I forgot to re-assign it back to the variable.

Works great! Good tip.