SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    May 2002
    Location
    Barcelona, Spain
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ereg_replace problem

    Hello PHP friends,

    PHP Code:
    I have this$fileNameReplaced eregi_replace("[^[:alnum:]]"""$fileName); 
    and it's good, but it replaces too many things. I want it to replace diacritical marks (tildes or accents in spanish , umlauts , strange scandinavian characaters they're strange for me, etc). But The above is getting rid of dots (.) which I want and dashes (-) and underscores (_).

    I'm sure there is a way to tell it to exclude these from the replacement. What's the magic?

    Thanks.
    Used to prefer PHP.
    Now I prefer Maya but stuck with PHP
    bruji.com

  2. #2
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should include \. - and _ in your expression if you do not wan to to replace them.
    Creativity knows no other restraint than the
    confines of a small mind.
    - Me
    Geekly Humor
    Oh baby! Check out the design patterns on that framework!

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You should also be using preg_replace, as the ereg functions are considered pretty much deprecated.

  4. #4
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raffles View Post
    You should also be using preg_replace, as the ereg functions are considered pretty much deprecated.
    They are deprecated as of PHP 5.3 and removed in PHP 6.

  5. #5
    SitePoint Evangelist
    Join Date
    May 2002
    Location
    Barcelona, Spain
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by imaginethis View Post
    You should include \. - and _ in your expression if you do not wan to to replace them.
    I've edit it to be this:

    $fileNameReplaced = eregi_replace("[^[:alnum:]\.\-\_]", "", $fileName);

    and it's still converting the dashes (-), keeps the dots and underscores thought so that's good.

    I thouht what the backslash did was escape special characters?
    Used to prefer PHP.
    Now I prefer Maya but stuck with PHP
    bruji.com


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
  •