News:

Free Image Hosting:
http://image-host.developers-heaven.net
Share your images free!!!

Main Menu

preg_replace allow space

Started by admin, August 22, 2009, 10:41:18 AM

Previous topic - Next topic

admin

$pattern = "/[^\d\w\s]/";
$replacement = "*";
$subject = "1 Main str, #5";

echo preg_replace($pattern, $replacement, $subject);

The ^ symbol negate a class. Right after this symbol we put the classes:

\d - digits
\w - words
\s - space

So, it reads as: "replace with * all the symbols from $subject, which are not digits, words and spaces".