SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: last ,

  1. #1
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    last ,

    How can I delete the last comma in a string??

    thanx

  2. #2
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    $newstr = ereg_replace(".*(,)[^,]*$", "", $string_to_replace_in);

    Tell me if that works...haven't tested it yet, but it seems logical.

  3. #3
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is simpler:
    PHP Code:
    $string ereg_replace (",$"""$string); 
    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry guys but neither one works. Seanf yours doesn't work because the comma would have to be the very last character i nthe string.

    qslack not sure why yours doesn't work but it doesn't. I tried to figure out a good solution with regex but I couldn't so here is my cheesy workaround.

    PHP Code:
    $string "Hello, I am a string, how do you like me, you say?";
    $string substr($string0strrpos($string",")).substr($stringstrrpos($string",") + 1strlen($string)); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

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