...

View Full Version : Explode to Extract Only Letters and Numbers



Xibe
08-07-2007, 10:50 PM
How can I explode a variable so that it takes out any punctuation (or anything that isn't a letter/number) and then saves the new content to a new variable.

Example:
-.Xibe.35- would return as: Xibe35

Please help!! :)

Thanks,
Xibe

mcjwb
08-08-2007, 12:42 AM
You can use regular expressions.


$string="-.Xibe.35-";
$pattern='/[^a-z0-9]/i'; //find everything that is not a letter(case insensitive) and not a number.
$replacement="";
print preg_replace($pattern,$replacement,$string);

Xibe
08-08-2007, 11:57 PM
Thanks a lot for helping me out there! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum