PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Fri Jun 23, 2006 12:07 am
I'm trying to think of where to start on this. I need a way to remove all characters from a string that aren't letters. (and a few other characters that I can add/remove occassionally) The string will be fairly large, upwards of 300k in some cases, so obviously I don't want to parse it character by character. Any ideas?
Thanks!
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jun 23, 2006 12:16 am
Code: Select all
$newstring = preg_replace('#[a-zA-Z]+#', '', $oldstring);
Robert Plank
Forum Contributor
Posts: 110 Joined: Sun Dec 26, 2004 9:04 pm
Contact:
Post
by Robert Plank » Fri Jun 23, 2006 9:56 am
feyd, Wouldn't that REMOVE the letters from the string... I was thinking more like:
Code: Select all
$newstring = preg_replace('#[^a-zA-Z]#', '', $oldstring);
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Fri Jun 23, 2006 10:19 am
Yep, Robert Plank has the correct solution. The first one will remove A-Za-z
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jun 23, 2006 10:23 am
I could have swore he said remove the letters....... hmm..
<- senile old man
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Fri Jun 23, 2006 10:25 am
feyd wrote: I could have swore he said remove the letters....... hmm..
<- senile old man
Hehe, yeah, i had to read it at least 7 times before my brain clicked
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Fri Jun 23, 2006 12:07 pm
Thanks guys I'll muck with the regex and try to add spaces and such. (I don't want all the spaces taken out). If I can't figure it out I'll ask.