doingword.com

Archive for October, 2006

Function to clear characters with php

Thursday, October 5th, 2006

Params:$s: Original text.
Return:The text without the specials chars

  1. function clearChars($s)
  2. {
  3.   //Array with the chars to remplace
  4.   $remplazos = Array
  5.   (
  6.     "[áàâãª]" => "a",
  7.     "[ÁÀÂÃ]"  => "A",
  8.     "[ÍÌÎ]"   => "I",
  9.     "[íìî]"   => "i",
  10.     "[éèê]"   => "e",
  11.     "[ÉÈÊ]"   => "E",
  12.     "[óòôõº]" => "o",
  13.     "[ÓÒÔÕ]"  => "O",
  14.     "[úùû]"   => "u",
  15.     "[ÚÙÛ]"   => "U",
  16.     "ç"       => "c",
  17.     "Ç"       => "C",
  18.     "[ñ]"     => "n",
  19.     "[Ñ]"     => "N"
  20.   );
  21.   foreach($remplazos AS $original => $remplazo)
  22.     $s = ereg_replace($original,$remplazo,$s);
  23.   return $s;
  24. }
[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Posted in Functions, Php | No Comments »