Regular expression - replace non printable chars with spaces

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Francesco

    Regular expression - replace non printable chars with spaces

    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\bibl io\newdoc.php on line 44

    Any suggestion?

    Thanks everyone!
    Francesco


  • Jon Kraft

    #2
    Re: Regular expression - replace non printable chars with spaces

    "Francesco" <fpiraneo(nospa m)@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\bibl io\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>


    HTH;
    JOn

    Comment

    Working...