Re: Striping unwanted characters from string
| From: | Steve Edberg | Date: | Tue, 12 Dec 2000 18:11:53 +0000 |
| Subject: | Re: Striping unwanted characters from string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-29916@lists.php.net to get a copy of this message | ||
At 3:49 PM -0200 12/12/00, Carlos Fernando wrote:
Hello All, I was wondering if someone could help me with this : I need to strip unwanted characters from a string. My system has a search script to search parts by partnumber. The Database only holds Partnumbers with characters from A to Z and 0 to 9. Alls characters such as blank space, -, _, * , @ , # & , {, } ,[ , ] : , ; '" should be ignored. The problem is that if a customer is looking for partnumber 1234 and he types 123-4 he ain't find anyhting. So I need a function to get a string parameter and return a result string with nothing but 0 to 9 and A to Z. I understarnd PHP has some built in string functions such as Trim() and ltrim() for blank spaces. Has anyone done this before? I would apreciate a few hints. thank you, Carlos Fernando Scheidecker Antunes$SanitizedString = ereg_replace('[^[:alnum:]]', '', $String); +--- "They've got a cherry pie there, that'll kill ya" ------------------+
| Steve Edberg University of California, Davis | | sbedberg@ucdavis.edu Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ |+-------------------------------------- FBI Special Agent Dale Cooper ---+