Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Removing all charachters in a string except...
Old 07-23-2006, 06:50 AM Removing all charachters in a string except...
Spin's Avatar
Super Talker

Posts: 113
Trades: 0
...a-z, 0-9 and spaces

Anyone? I'm stuck here.
Spin is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-23-2006, 09:27 AM Re: Removing all charachters in a string except...
Average Talker

Posts: 15
Trades: 0
Code:
$input = ereg_replace("[^0-9a-Z ]", "", $input);
Think that does it!
__________________
Paul

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
Paul_F is offline
Reply With Quote
View Public Profile Visit Paul_F's homepage!
 
Old 07-23-2006, 09:54 AM Re: Removing all charachters in a string except...
Spin's Avatar
Super Talker

Posts: 113
Trades: 0
Thanks!
Spin is offline
Reply With Quote
View Public Profile
 
Old 07-23-2006, 10:19 AM Re: Removing all charachters in a string except...
Ultra Talker

Posts: 256
Location: Auckland, New Zealand
Trades: 0
Actually Paul F's pattern is incorrect, a-Z is a larger range than what you want.

Just for performance, preg_replace is faster than ereg_replace, though I'm not sure whether using modifiers for case sensitivity is faster or not, in my tests it made marginal difference.

PHP Code:
$input preg_replace('/[^a-zA-Z0-9 ]/'''$input); 
Cheers,

MC
__________________
#------------------------------signature---------------------------------------------------------------------------------#
Quote:
I am well recognised for what I don't do than what I do. Chores are just one of those things.

Last edited by mastercomputers; 08-17-2006 at 01:39 AM..
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
Old 07-23-2006, 10:48 AM Re: Removing all charachters in a string except...
Spin's Avatar
Super Talker

Posts: 113
Trades: 0
BTW, got an e-mail from a friend, he suggested
PHP Code:
preg_replace('/[^0-9a-z ]/i','',$input); 
Spin is offline
Reply With Quote
View Public Profile
 
Old 07-23-2006, 07:18 PM Re: Removing all charachters in a string except...
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
The i modifier just makes it case insensitive.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Removing all charachters in a string except...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22453 seconds with 12 queries