SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot Coastal Web's Avatar
    Join Date
    Jan 2006
    Location
    Oregon, U.S.
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    easy preg_replace help?

    Hi guys, l have a few strings for example:

    testing+123
    testing+1+2+3

    What l'd like to do is strip off the + signs and anything after them,
    So in this example both strings would become 'testing'

    Can anyone help me with a preg_replace that would solve this problem for me?

    Regards,

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    ~\+.*$~
    is your pattern.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Zealot Coastal Web's Avatar
    Join Date
    Jan 2006
    Location
    Oregon, U.S.
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help, l'm still doing something wrong, so here's what l'm running:

    PHP Code:
    $string 'test+123';
    $stringpreg_replace('~+.*$~'''$string); 
    But it's not doing anything. I would it expect it to return 'test'

    Regards,

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,127
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    You forgot the \ in front of the +
    PHP Code:
    $string 'test+123'
    $stringpreg_replace('~\+.*$~'''$string); //need to escape the + 

  5. #5
    SitePoint Zealot Coastal Web's Avatar
    Join Date
    Jan 2006
    Location
    Oregon, U.S.
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome, thanks again!


Tags for this Thread

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
  •