Professional Web Applications Themes

Regular expression - replace non printable chars with spaces - PHP Development

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("(

Thread: Regular expression - replace non printable chars with spaces

-7)|(
77-77)", "0", $_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...

  1. #1

    Default 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\biblio\newdoc.php on line 44

    Any suggestion?

    Thanks everyone!
    Francesco


    Francesco Guest

  2. #2

    Default 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\biblio\newdoc.php on line 44

    Any suggestion?

    Thanks everyone!
    Francesco


    Francesco Guest

  3. #3

    Default Re: Regular expression - replace non printable chars with spaces

    "Francesco" <fpiraneo(nospam)libero.it> wrote:
    > (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
    <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>
    [url]http://uk.php.net/manual/en/ref.pcre.php[/url]

    HTH;
    JOn
    Jon Kraft Guest

  4. #4

    Default Re: Regular expression - replace non printable chars with spaces

    *** Francesconospam wrote/escribió (Mon, 01 Dec 2003 14:08:32 GMT):
    > 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).
    Try something like this:

    preg_replace( '/[^[:print:]]+/', ' ', $text)




    --
    --
    -- Álvaro G. Vicario - Burgos, Spain
    --
    Alvaro G Vicario Guest

Similar Threads

  1. replace spaces with 0's in a string
    By weezerboy in forum Macromedia ColdFusion
    Replies: 1
    Last Post: February 16th, 09:56 PM
  2. Replace with regular expression
    By Wiggins D'Anconia in forum PERL Beginners
    Replies: 3
    Last Post: November 14th, 03:17 PM
  3. How to replace variable spaces with a tab - Please Help
    By Perlwannabe in forum PERL Beginners
    Replies: 2
    Last Post: September 6th, 11:47 PM
  4. [PHP] REGULAR EXPRESSION HELP
    By John W. Holmes in forum PHP Development
    Replies: 3
    Last Post: July 14th, 01:23 PM
  5. how to replace urls in a doent (with regular expression)
    By Curious Expatriate in forum PHP Development
    Replies: 3
    Last Post: July 3rd, 04:25 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •