Powered by InterCreatives | Site Map
Search:
NewSourceMedia Popular Tutorials: PHP Javascripts Web Hosting
SoftwareTutorials
CATEGORIES
Job Listings
 
Home / PHP / Content Management

Php Remove Non-Alphanumeric Characters

Published by: Alexander Mclean III


Need help removing un-wanted characters from your php text form strings. Here's how to strip a string of all symbols and characters other than alphanumeric letters and numbers from your file or database. This code will delete any non-alphanumeric characters specified between the brackets, and then output/return the clean version.

The code


<?php

$string
= "Here! is some text, and numbers 12345, and symbols !£$%^&";

$new_string = preg_replace("/[^a-zA-Z0-9s]/", "", $string);

echo
$new_string

?>


The code should return this:

Here is some text and numbers 12345 and symbols

One more thing. If you don't like to keep the blank white space in your text just reformat the preg_replace by removing the "s" whitespace character types. This is good for use with user names and passwords. The code would now look something like this:

Hereissometextandnumbers12345andsymbols


Next PHP Page:
1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  [25]  26  27  28  29  30  31  32 





Hosting by iPowerWeb.com - 50 Gb for $7.95