Connecting Tech Pros Worldwide Help | Site Map

Regular expression - replace non printable chars with spaces

Francesco
Guest
 
Posts: n/a
#1: Jul 17 '05
I've created a form asking a user to enter a text; the user can press
[enter] key or any other "strange" non printable char that i want to strip
away from the entred text and replace it with a " " (whitespace).
I've prepared a line with preg_preplace function but it seem doesn't work.

By the way:

$oggetto = preg_replace("(\0-\037)|(\0177-\0377)", "\040",
$_POST['oggetto']);

The result is:

Warning: No ending matching delimiter ')' found in
E:\WWWTest\biblio\newdoc.php on line 44

Any suggestion?

Thanks everyone!
Francesco


Jon Kraft
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Regular expression - replace non printable chars with spaces


"Francesco" <fpiraneo(nospam)@libero.it> wrote:
[color=blue]
> (whitespace). I've prepared a line with preg_preplace function but it
> seem doesn't work.
>
> $oggetto = preg_replace("(\0-\037)|(\0177-\0377)", "\040",
> $_POST['oggetto']);
>
> The result is:
>
> Warning: No ending matching delimiter ')' found in
> E:\WWWTest\biblio\newdoc.php on line 44[/color]

<quote>
The syntax for patterns used in these functions closely resembles Perl.
The expression should be enclosed in the delimiters, a forward slash (/),
for example. Any character can be used for delimiter as long as it's not
alphanumeric or backslash (\). If the delimiter character has to be used
in the expression itself, it needs to be escaped by backslash. Since PHP
4.0.4, you can also use Perl-style (), {}, [], and <> matching delimiters.
</quote>
http://uk.php.net/manual/en/ref.pcre.php

HTH;
JOn
Closed Thread