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
pedrotuga
Forum Contributor
Posts: 249 Joined: Tue Dec 13, 2005 11:08 pm
Post
by pedrotuga » Wed Nov 15, 2006 9:06 pm
Ok, i promise i will learn REGEX soon.
I need to clean strings so only A-Z a-z and 0-9 stay on the string, the remain characters will be replaced by spaces or underscores.
is there anyway of doing this using regex or should i loop the string character by character and check if it«s valid?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Nov 15, 2006 9:10 pm
Of course there's a way to do it with regex. Try something first and post it. We'll tell you where you've gone wrong or suggest changes accordingly. Or you could just look through all the threads in the Regex forum .
pedrotuga
Forum Contributor
Posts: 249 Joined: Tue Dec 13, 2005 11:08 pm
Post
by pedrotuga » Wed Nov 15, 2006 9:41 pm
Ok... it was easier than i expected, i didnt know with function to use... i searched for "replace" on php-net.
Code: Select all
<?php
$string = ereg_replace("[^A-Za-z0-9]", " ", $string);
?>
any issue on that line of code?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Nov 15, 2006 9:46 pm
Other than using ereg instead of preg, nope.
pedrotuga
Forum Contributor
Posts: 249 Joined: Tue Dec 13, 2005 11:08 pm
Post
by pedrotuga » Wed Nov 15, 2006 9:49 pm
feyd wrote: Other than using ereg instead of preg, nope.
in practical terms what would the diference be in this case?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Nov 15, 2006 9:50 pm
Performance and future compatibility.