preg_replace

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • correo@ironcito.com

    preg_replace

    Hi all!

    This:

    $string = preg_replace('/[^a-z\d\s]/i', '_', $string);

    replaces an accented letter with two underscores instead of one, when
    the submitting page is in UTF8 ($string comes from a GET form). It
    works well when the submitting page is encoded in ISO-8859-1 or with
    other characters such as an ampersand or whatever. Any ideas why? TIA

    Diego

  • Pedro Graca

    #2
    Re: preg_replace

    correo@ironcito .com wrote:[color=blue]
    > $string = preg_replace('/[^a-z\d\s]/i', '_', $string);
    >
    > replaces an accented letter with two underscores instead of one, when
    > the submitting page is in UTF8 ($string comes from a GET form). It
    > works well when the submitting page is encoded in ISO-8859-1 or with
    > other characters such as an ampersand or whatever. Any ideas why? TIA[/color]

    Because you didn't specify that you want pattern strings treated as
    UTF-8. Use the `u` modifier

    preg_replace('//u', ...)

    --
    Mail to my "From:" address is readable by all at http://www.dodgeit.com/
    == ** ## !! ------------------------------------------------ !! ## ** ==
    TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
    may bypass my spam filter. If it does, I may reply from another address!

    Comment

    Working...