str_replace Case Sensitive Problem

When i use str_replace for replacement in PHP, it is changing without any case sensitive. Example i want to bold HousE, code is

<?
$text = "I like my house.";
$string = "HousE";
$text = str_replace($string,"<b>$string</b>",$text);
echo($text);
?>

Php 5 have another function to solve this problem str_ireplace() . But this is solve my problem exactly. Because i want to replace case sensitive to case sensitive.  I found this solution for my problem. I hope you’ll enjoy.


function ext_str_ireplace($findme, $replacewith, $subject)
{
     // Replaces $findme in $subject with $replacewith
     // Ignores the case and do keep the original capitalization by using $1 in $replacewith
     // Required: PHP 5

     $rest = $subject;
     $result = '';

     while (stripos($rest, $findme) !== false) {
          $pos = stripos($rest, $findme);

          // Remove the wanted string from $rest and append it to $result
          $result .= substr($rest, 0, $pos);
          $rest = substr($rest, $pos, strlen($rest)-$pos);

          // Remove the wanted string from $rest and place it correctly into $result
          $result .= str_replace('$1', substr($rest, 0, strlen($findme)), $replacewith);
          $rest = substr($rest, strlen($findme), strlen($rest)-strlen($findme));
     }

     // After the last match, append the rest
     $result .= $rest;

     return $result;
}

Converting Unescape Chars in MySQL for SEO

Sometimes, i need to convert datas for search engine optimization (SEO). I use MySQL replace command for this. Just login to phpmyadmin or any tool for run SQL command. Paste command set, change table and field name than run.

UPDATE table SET field = replace(field, 'À','A');
UPDATE table SET field = replace(field, 'Á','A');
UPDATE table SET field = replace(field, 'Â','A');
UPDATE table SET field = replace(field, 'Ã','A');
UPDATE table SET field = replace(field, 'Ä','A');
UPDATE table SET field = replace(field, 'Å','A');
UPDATE table SET field = replace(field, 'Æ','AE');
UPDATE table SET field = replace(field, 'Ç','C');
UPDATE table SET field = replace(field, 'È','E');
UPDATE table SET field = replace(field, 'É','E');
UPDATE table SET field = replace(field, 'Ê','E');
UPDATE table SET field = replace(field, 'Ë','E');
UPDATE table SET field = replace(field, 'Ì','I');
UPDATE table SET field = replace(field, 'Í','I');
UPDATE table SET field = replace(field, 'Î','I');
UPDATE table SET field = replace(field, 'Ï','I');
UPDATE table SET field = replace(field, 'Ò','O');
UPDATE table SET field = replace(field, 'Ó','O');
UPDATE table SET field = replace(field, 'Ô','O');
UPDATE table SET field = replace(field, 'Õ','O');
UPDATE table SET field = replace(field, 'Ö','O');
UPDATE table SET field = replace(field, '×','Z');
UPDATE table SET field = replace(field, 'Ø','O');
UPDATE table SET field = replace(field, 'Ù','U');
UPDATE table SET field = replace(field, 'Ú','U');
UPDATE table SET field = replace(field, 'Û','U');
UPDATE table SET field = replace(field, 'Ü','U');
UPDATE table SET field = replace(field, 'ß','ss');
UPDATE table SET field = replace(field, 'à','a');
UPDATE table SET field = replace(field, 'á','a');
UPDATE table SET field = replace(field, 'â','a');
UPDATE table SET field = replace(field, 'ã','a');
UPDATE table SET field = replace(field, 'ä','a');
UPDATE table SET field = replace(field, 'å','a');
UPDATE table SET field = replace(field, 'æ','ae');
UPDATE table SET field = replace(field, 'ç','c');
UPDATE table SET field = replace(field, 'è','e');
UPDATE table SET field = replace(field, 'é','e');
UPDATE table SET field = replace(field, 'ê','e');
UPDATE table SET field = replace(field, 'ë','e');
UPDATE table SET field = replace(field, 'ì','i');
UPDATE table SET field = replace(field, 'í','i');
UPDATE table SET field = replace(field, 'î','i');
UPDATE table SET field = replace(field, 'ï','i');
UPDATE table SET field = replace(field, 'ñ','n');
UPDATE table SET field = replace(field, 'ü','u');
UPDATE table SET field = replace(field, 'ò','o');
UPDATE table SET field = replace(field, 'ó','o');
UPDATE table SET field = replace(field, 'ô','o');
UPDATE table SET field = replace(field, 'õ','o');
UPDATE table SET field = replace(field, 'ö','o');
UPDATE table SET field = replace(field, 'ø','o');
UPDATE table SET field = replace(field, 'ù','u');
UPDATE table SET field = replace(field, 'ú','u');
UPDATE table SET field = replace(field, 'û','u');
UPDATE table SET field = replace(field, 'ÿ','y');