SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Nov 2001
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How would I change accented characters to non-acceted equivalents?

    Basically, I had a huge tab-delimited text file, which I used OpenOffice to convert into CVS, then phpmyadmin to put into the database. Some of the names have accented characters such as the french-style 'e' in 'cafe'.

    So it looks like this: Butterfly Caf�

    I want to convert those characters so the name becomes Butterfly Cafe (no accent). I tried doing a str_replace(), but when I copy and paste '�' it doesn't actually find that string to replace, so obviously it's different, such as a character code or something like that and I'm just seeing a representation of it.

    Any ideas on how to go about doing this?

  2. #2
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This function is by no means foolproof. It appears to work on german/french but I know for a fact it doesn't work on slovakian. Good luck:

    PHP Code:
    function remove_accents($text)
    {
        
    $trans get_html_translation_table(HTML_ENTITIES);
        foreach(
    $trans as $literal =>$entity)
        {
               if(
    ord($literal) >= 192)
               { 
                     
    $replace[] = substr($entity11); 
                     
    $search[] = $literal;
                 }
             } 
        return 
    str_replace($search$replace$text);



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
  •