#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    More PHP preg_replace troubles...


    Okay, here's an example of what I've got:

    PHP Code:
    preg_replace("/, ^/",".","A, B, C, D, "); 
    I want it to return this:

    "A, B, C, D."

    ... But it doesn't. It just returns "A, B, C, D, ".

    But why? And how can I fix my problem?
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,113
    Rep Power
    9398
    ^ is the beginning of the string. You want the end of it: $.

    But
    PHP Code:
    rtrim("A, B, C, D, "", ") . "." 
    is better. Or, depending on how you got that list,
    PHP Code:
    $list = array("A""B""C""D");
    implode(", "$list

    Comments on this post

    • ManiacDan agrees
    • ishnid agrees

IMN logo majestic logo threadwatch logo seochat tools logo