how to remove all non-letters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kevin bailey

    how to remove all non-letters

    hi,

    it's really late and i'm struggling with this one - so any help gratefully
    received.

    if i have a string how would i strip out all characters except letters
    between a-z and A-Z

    i presume this would be using preg_grep but not being a regex guru is making
    it hard.

    would it be something like?


    $subject = "abc-d%ef"; // Want i want to get back is 'abcdef'
    $pattern = '/[a-zA-Z]*/';
    preg_match($pat tern, $subject, $matches);
    // print_r($matche s);

    $cleaned_word = matches[0];


    thanks,

    kev
  • Mike Youell

    #2
    Re: how to remove all non-letters


    I'd use preg_replace() instead:

    $subject = "abc-d%ef"; // Want i want to get back is 'abcdef'

    $pattern = '/[^a-zA-Z]*/';
    echo preg_replace($p attern, '', $subject);

    Cheers,
    Mike Youell.

    Comment

    • kevin bailey

      #3
      Re: how to remove all non-letters

      Mike Youell wrote:
      [color=blue]
      >
      > I'd use preg_replace() instead:
      >
      > $subject = "abc-d%ef"; // Want i want to get back is 'abcdef'
      >
      > $pattern = '/[^a-zA-Z]*/';
      > echo preg_replace($p attern, '', $subject);
      >
      > Cheers,
      > Mike Youell.[/color]


      Thanks for that.

      kev

      Comment

      Working...