Re: Any Ideas
| From: | Steve Edberg | Date: | Sun, 27 Jan 2002 00:18:53 +0000 |
| Subject: | Re: Any Ideas | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-82260@lists.php.net to get a copy of this message | ||
Or do it all in one line:
$string = ereg_replace('[!@#$%^&*()_+=-';:"/.,<>?]', '', $string);
If you want to remove non-alphanumeric characters from a string, you can do:
$string = ereg_replace('[^[:alnum:]]', '', $string);
Perl-compatible regular expressions would work as well, and be slightly faster. For more info, see:
http://www.php.net/manual/en/function.ereg.php
http://www.php.net/manual/en/ref.regex.php
http://www.php.net/manual/en/ref.pcre.php
-steve
At 12:21 PM -0800 1/26/02, "qartis" <brokenkitty@hotmail.com> wrote:
I'm guessing something along the lines of: -- $string=str_replace("!","",$string); $string=str_replace("@","",$string); $string=str_replace("#","",$string); $string=str_replace("$","",$string); $string=str_replace("%","",$string); $string=str_replace("^","",$string); -- etc. "Philip J. Newman" <newmanpj@philipsdomain.com> wrote in message news:003d01c1a6a5$fa7d60e0$0401a8c0@philip... Any Ideas how I can remove !@#$%^&*()_+=-';:"/.,<>? charactors from a string? Philip J. Newman Philip's Domain - Internet Project. http://www.philipsdomain.com/ info@philipsdomain.com Phone: +64 25 6144012-- +------------------------------------------------------------------------+ | Steve Edberg sbedberg@ucdavis.edu | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | +------------------------------------------------------------------------+ | "Restriction of free thought and free speech is the most dangerous of | | all subversions. It is the one un-American act that could most easily | | defeat us." | | - Supreme Court Justice (1939-1975) William O. Douglas | +------------------------------------------------------------------------+