SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  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)

    ereg_replace error...HELP!

    I ran the regex:

    [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*

    which is found at http://php.net/manual/en/language.variables.php

    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 which I belive are a charecter set. It should run fine though, if the php site itself displays the regex. How do I fix this? Thanks.

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

    Anyone???

  3. #3
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What exactly are you trying to accomplish with this? I'm not quite sure why it's producing the error, but maybe I could re-write it to your needs.
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  4. #4
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am trying to take a string, and replace any charecters that are not allowed in a variable name with a "_".

    The list of charecters allowed in a variable name are found at http://php.net/manual/en/language.variables.php

    I should be able to just do $file_safe=eregi_replace[^a-zA-Z0-9_\x7f-\xff]", "_", $file); but it produces those errors I posted before.

    Any help is appreciated...thanks!

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Regular Expressions aren't exactly my forte but I think this should work. Maybe Anarchos can shed some ligh on how to combine these two.

    Code:
    $filename = preg_replace("/^([0-9]{1})/S", "_", $filename);
    $filename = preg_replace("/([^a-zA-Z0-9\x7f-\xff]{1})/S", "_", $filename);
    Last edited by freddydoesphp; Sep 3, 2001 at 13:07.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whats the difference between preg and ereg?

  7. #7
    SitePoint Member
    Join Date
    Aug 2001
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    preg takes perl-compatible regular expressions, rather than POSIX(Which is what ereg uses).

    http://www.php.net:8000/manual/en/html/ref.pcre.html
    http://www.php.net:8000/manual/en/html/ref.regex.html
    signature

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

    I tried the ereg with [^a-zA-Z0-9_x7f-xff] and it worked, so it had something to do with the slashes before the x's?

    Anyways, I rewrote that section of the script so it doesn't even need to even use regular expressions anymore and it works perfectly now.

    But thanks for everyones help!


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
  •