Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2006
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating delimiters...standard solution?

    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.

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,009
    Thanks
    2
    Thanked 312 Times in 304 Posts
    Easy way: Use one of the trim functions (ltrim, trim, rtrim) and list your delimiter in the string charlist parameter.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Regular Coder
    Join Date
    May 2006
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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??

  • #4
    Regular Coder
    Join Date
    May 2006
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nevermind...

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

    Works great! Good tip.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •