scriptingBlog.com - For those who work online
Do you have something interesting to share with others? If you do, click here to write a post or a press-release to the blog. All 100% free!

Remove Letter Accents from Text

This function will translates all accented characters, from a string, to their non-accented equivalents.

Source code:


<?
function remove_accents($str) {
  $str htmlentities($strENT_COMPAT"UTF-8");
  $str preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde|cedil|ring);/','$1',$str);
  $from explode(" ""&#192; &#193; &#194; &#195; &#196; &#197; &#199; &#200; &#201; &#202; &#203; &#204; &#205; &#206; &#207; &#208; &#209; &#210; &#211; &#212; &#213; &#214; &#217; &#218; &#219; &#220; &#221; &#224; &#225; &#226; &#227; &#228; &#229; &#230; &#231; &#232; &#233; &#234; &#235; &#236; &#237; &#238; &#239; &#240; &#241; &#242; &#243; &#244; &#245; &#246; &#249; &#250; &#251; &#252; &#253; &#255; &#256; &#257; &#258; &#259; &#260; &#261; &#262; &#263; &#264; &#265; &#266; &#267; &#268; &#269; &#270; &#271; &#272; &#273; &#274; &#275; &#276; &#277; &#278; &#279; &#280; &#281; &#282; &#283; &#284; &#285; &#286; &#287; &#288; &#289; &#290; &#291; &#292; &#293; &#294; &#295; &#296; &#297; &#298; &#299; &#300; &#301; &#302; &#303; &#304; &#305; &#308; &#309; &#310; &#311; &#312; &#313; &#314; &#315; &#316; &#317; &#318; &#319; &#320; &#321; &#322; &#323; &#324; &#325; &#326; &#327; &#328; &#329; &#330; &#331; &#332; &#333; &#334; &#335; &#336; &#337; &#340; &#341; &#342; &#343; &#344; &#345; &#346; &#347; &#348; &#349; &#350; &#351; &#352; &#353; &#354; &#355; &#356; &#357; &#360; &#361; &#362; &#363; &#364; &#365; &#366; &#367; &#368; &#369; &#370; &#371; &#372; &#373; &#374; &#375; &#376; &#377; &#378; &#379; &#380; &#381; &#382; ă î â ș ț Ă Î Â Ș Ț Äƒ Ã® Ã¢ ÅŸ Å£ Ä‚ ÃŽ Ã‚ Åž Å¢");
  $to explode(" ""A A A A A A C E E E E I I I I D N O O O O O U U U U Y a a a a a a a c e e e e i i i i o n o o o o o u u u u y y A a A a A a C c C c C c C c D d D d E e E e E e E e E e G g G g G g G g G H H h I i I i I i I i I i J j K k k L l L l L l L l L l N n N n N n n N n O o O o O o R r R r R r S s S s S s S s T t T t U u U u U u U u U u U u W w Y y Y Z z Z z Z z a i a s t A I A S T a i a s t A I A S T");
  return str_replace($from$tohtml_entity_decode($str));
}
?>

Tags: ,

2 Responses to “Remove Letter Accents from Text”

  1. Kek Says:

    EXELENT!!! muchas gracias!! funciona mejor que los otros que he visto.

  2. Guillermo Says:

    Absolutely excellent function! Thanks a lot! :D
    Wouldn’t it be better if the $from and $to were already an array instead of being exploded?
    (see: http://pastebin.com/f33332c83)

    Cheers!

Leave a Reply