View Full Version : Delete anything not alphanumeric
schleppel
03-14-2005, 07:31 PM
The title says it, i would like to know how i would go about deleting anything in a string that is not a-z A-Z or 0-9.
Thank you.
marek_mar
03-14-2005, 08:10 PM
I'm actualy suggesting regex...
<?
$txt ='hell!o 108 dDFfdofig';
preg_match_all('/[a-zA-Z0-9]/', $txt, $txt);
$txt = implode('', $txt[0]);
print $txt; // Output: hello108dDFfdofig
?>
schleppel
03-14-2005, 08:14 PM
Thank you, that's perfect!
hemebond
03-14-2005, 09:00 PM
<?php
$string = preg_replace('([^a-zA-Z0-9 ])', '', 'This is a g%^73(7634 string');
echo $string;
?>
schleppel
03-14-2005, 09:55 PM
Thank you aswell.
marek_mar
03-14-2005, 09:56 PM
Hoebond's version is probably better...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.