Jump to content


Photo

Remove all non-alphabetical characters


  • Please log in to reply
2 replies to this topic

#1 kevinkorb

kevinkorb
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts
  • LocationSt. Louis, MO

Posted 18 July 2006 - 08:57 PM

$string = 'the rapist 4';

I want to remove all non-alpha characters to produce

$new_string = 'therapist';

Thanks a bunch... I'm sure this is cake for most of you. 

#2 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 18 July 2006 - 09:00 PM

<?php
$string = 'the rapist 4';
$string = preg_replace('/[^a-zA-Z]/', '', $string);
echo $string;
?>


#3 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 18 July 2006 - 09:59 PM

Are you only working with ASCII?
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users