You are here: Re: Regex help !!!! « PHP Programming Language « IT news, forums, messages
Re: Regex help !!!!

Posted by Rik Wasmus on 09/12/07 12:50

On Wed, 12 Sep 2007 14:43:38 +0200, Moham12345 <m_w_raza@hotmail.com> =

wrote:

> Im having problems with a regex. I am trying to do a preg_replace on a=

> string using a regular expression which replaces a non A-Z, a-z, 0-9
> character with "" (empty string" . In other words i just want to
> remove all non A-Z, a-z and 0-9 characters. However spaces are ok.

$string =3D preg_replace('/[^a-z0-9 ]/i','',$string);

Allthough, depending on the exact yse, you might be better served with:
$string =3D preg_replace('/[^\w ]/i','',$string);

From the manual about '\w':
"A "word" character is any letter or digit or the underscore character, =
=

that is, any character which can be part of a Perl "word". The definitio=
n =

of letters and digits is controlled by PCRE's character tables, and may =
=

vary if locale-specific matching is taking place. For example, in the "f=
r" =

(French) locale, some character codes greater than 128 are used for =

accented letters, and these are matched by \w."
-- =

Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация