Home » , » Remove special characters from php string

Remove special characters from php string

Written By Unknown on Kamis, 28 April 2011 | 01.09

Hello friends. At some point we need to filter our strings and remove some unwanted characters from the string for some purpose. It is quite easy to do this with regular expressions.

Php built-in function preg_replace() can be used to remove special characters from a string. It takes 3 parameters and its syntax is

$output = preg_replace(pattern, replacWith, string);

Remove all characters except alphabets and digits use this.



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

Remove all ascii characters from the string use this.



$output=preg_replace('/[^(\x20-\x7f)]*/s','',$string);

Share this article :

Posting Komentar

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger