SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    regex question...

    Is there a way using eregi_replace to replace all charecters that are NOT included in a set with something else.

    For example, is there a way to replace all charecters in $var that are NOT [a-zA-Z0-9_\x7f-\xff] with "_"

    So something like eregi_replace(![a-zA-Z0-9_\x7f-\xff], "_", $string) ...

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, stick a ^ at the beginning of the character class. like this (and i use preg_replace()):

    PHP Code:
    preg_replace('/[^a-z0-9_\x7f-\xff]/i''_'$txt); 
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  3. #3
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This looks like it is gonna work pefect! Thanks.

    One more question though: I ran the regex found at http://php.net/manual/en/language.variables.php which is [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]* and it gave me these errors:

    Warning: REG_ERANGE: in c:\my documents\nate\sites\projects\jumpthru mailman\admin\import.php on line 27

    Warning: REG_ERANGE:invalid character range in c:\my documents\nate\sites\projects\jumpthru mailman\admin\import.php on line 27

    Line 27 is this:

    $file_safe=eregi_replace("[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*", "_", $file);

    It has something do to with the \x7f-\xff. How do I fix this? Thanks.
    Last edited by jumpthru; Aug 31, 2001 at 00:46.


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
  •