Strip Down Strings

Discussion in 'PHP' started by Linkbait, Jan 6, 2007.

  1. #1
    I need to know how I can remove letters and all symbols except periods "." from a string.

    Thanks.
     
    Linkbait, Jan 6, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    You just want to allow periods?

    
    
    $text = preg_replace('/[^\.]/', null, $text);
    
    PHP:
     
    nico_swd, Jan 6, 2007 IP
    KC TAN likes this.
  3. Linkbait

    Linkbait Peon

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Only numbers and periods... That example sort of works but it only leaves the periods.
     
    Linkbait, Jan 6, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    
    
    $text = preg_replace('/[^\.0-9]/', null, $text);
    
    PHP:
     
    nico_swd, Jan 6, 2007 IP
  5. Linkbait

    Linkbait Peon

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks man that worked great.

    Now, for future reference, what would that string look like if I wanted just periods, numbers, and commas?
     
    Linkbait, Jan 6, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Like this.
    
    '/[^\.\,0-9]/'
    
    PHP:
     
    nico_swd, Jan 6, 2007 IP
  7. technoguy

    technoguy Notable Member

    Messages:
    4,369
    Likes Received:
    306
    Best Answers:
    0
    Trophy Points:
    205
    #7
    Use this I hope it will help you to solve your problem.

    $text = preg_replace('/[^\.0-9]/', null, $text);

    If you hve a problem let me know.

    thanks
     
    technoguy, Jan 6, 2007 IP
  8. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #8
    ^^ This is exactly what I posted before?
     
    nico_swd, Jan 6, 2007 IP
  9. KC TAN

    KC TAN Well-Known Member

    Messages:
    4,792
    Likes Received:
    353
    Best Answers:
    0
    Trophy Points:
    155
    #9
    Always as helpful :) Thanks, nico_swd.
     
    KC TAN, Jan 7, 2007 IP
  10. Linkbait

    Linkbait Peon

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Yeah nico I had it working after your second post. I just asked how I would add the "," to that so I know how to use the function. I was unclear on how to sort out certain things.
     
    Linkbait, Jan 8, 2007 IP