Reply LinkBack Thread Tools Search this Thread
Old 22-10-2006, 12:33   #1 (permalink)
tobor
Senior Member
 
tobor's Avatar
 
Join Date: Apr 2005
Location: Toronto, Canada
Posts: 162
Replace accented characrters with non-accented characters in PHP

From é ê è to e?
Anyone know how, nothing is working for me right now.
I suck at regular expresions.
  Reply With Quote
Old 22-10-2006, 12:39   #2 (permalink)
tobor
Senior Member
 
tobor's Avatar
 
Join Date: Apr 2005
Location: Toronto, Canada
Posts: 162
had a coffee... figured it out.
  Reply With Quote
Old 22-10-2006, 14:51   #3 (permalink)
Larixk
Senior Member
 
Larixk's Avatar
 
Join Date: Sep 2006
Location: Utrecht, Netherlands
Posts: 1,025
Send a message via MSN to Larixk
care to share for future users who search with the same problem and stumble upon this topic?
  Reply With Quote
Old 23-10-2006, 01:04   #4 (permalink)
tobor
Senior Member
 
tobor's Avatar
 
Join Date: Apr 2005
Location: Toronto, Canada
Posts: 162
PHP Code:
// create function to remove accents
    
function removeAccents($remove_from)
    {
        
// Remove all instances of accents
        
$accent_array = array(
            
'e' => array('é','è','ê','ë'),
            
'E' => array('É','È','Ê','Ë'),
            
'a' => array('á','à','â','ä','å'),
            
'A' => array('Á','À','Â','Ä','Å')
        );
        foreach(
$accent_array as $acc_key => $acc_val_array)
        {
            
$reg_exp_accent '';// clear regular expression var
            
for($m=0;$m<count($acc_val_array);$m++)
            {
                
$reg_exp_accent .= $acc_val_array[$m].'|';// create the regular expression var
            
}
            
$reg_exp_accent substr_replace($reg_exp_accent,"",-1);// remove last '|'
            
            
$remove_from ereg_replace($reg_exp_accent,$acc_key,$remove_from);
        }
        
        return 
$remove_from;
    } 

not the greatest thing ever, but working...

Example of use:
PHP Code:
removeAccents($_POST['french_text']); 
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8