Thứ Năm, 22 tháng 8, 2013

chuyển chuỗi in hoa thành in thường php / string to lowercase php (vietnamese)


function tolower_vnm($str) {
    $u = array(
        'Ú', 'Ù', 'Ủ', 'Ũ', 'Ụ', 'U',
        'Ứ', 'Ừ', 'Ử', 'Ữ', 'Ự', 'Ư',
    );
    $u1 = array(
        'ú', 'ù', 'ủ', 'ũ', 'ụ', 'u',
        'ứ', 'ừ', 'ử', 'ữ', 'ự', 'ư');
    $a = array(
        'Á', 'À', 'Ả', 'Ã', 'Ạ', 'A',
        'Ắ', 'Ằ', 'Ẩ', 'Ẵ', 'Ặ', 'Ă',
        'Ấ', 'Ầ', 'Ẩ', 'Ẫ', 'Ậ', 'Â',
    );
    $a1 = array(
        'á', 'à', 'ả', 'ã', 'ạ', 'a',
        'ắ', 'ằ', 'ẳ', 'ẵ', 'ặ', 'ă',
        'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'â');
    $e = array(
        'É', 'È', 'Ẻ', 'Ẽ', 'Ẹ', 'E',
        'Ế', 'Ề', 'Ể', 'Ễ', 'Ệ', 'Ê',
    );
    $e1 = array(
        'é', 'è', 'ẻ', 'ẽ', 'ẹ', 'e',
        'ế', 'ề', 'ể', 'ễ', 'ệ', 'ê'
    );
    $o = array(
        'Ó', 'Ò', 'Ỏ', 'Õ', 'Ọ', 'O',
        'Ố', 'Ồ', 'Ỗ', 'Ỗ', 'Ộ', 'Ô',
        'Ớ', 'Ờ', 'Ỡ', 'Ỡ', 'Ợ', 'Ơ',
    );
    $o1 = array(
        'ó', 'ò', 'ỏ', 'õ', 'ọ', 'o',
        'ố', 'ồ', 'ổ', 'ỗ', 'ộ', 'ô',
        'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ơ'
    );
    $ii = array(
        'Í', 'Ì', 'Ỉ', 'Ĩ', 'Ị', 'I',
    );
    $ii1 = array(
        'í', 'ì', 'ỉ', 'ĩ', 'ị', 'i',
    );
    $y = array(
        'Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Y',
    );
    $y1 = array(
        'ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'y'
    );
    $d = array('Đ',
    );
    $d1 = array(
        'đ');

    $count = count($a);
    for ($i = 0; $i < $count; $i++) {
        $str = str_replace($a[$i], $a1[$i], $str);
    }

//    $str = str_replace($a, 'a', $str);
    $count = count($e);
    for ($i = 0; $i < $count; $i++) {
        $str = str_replace($e[$i], $e1[$i], $str);
    }
//    $str = str_replace($e, 'e', $str);
    $count = count($d);
    for ($i = 0; $i < $count; $i++) {
        $str = str_replace($e[$i], $e1[$i], $str);
    }
//    $str = str_replace($d, 'd', $str);
     $count = count($o);
    for ($i = 0; $i < $count; $i++) {
        $str = str_replace($o[$i], $o1[$i], $str);
    }
//    $str = str_replace($o, 'o', $str);
    $count = count($u);
    for ($i = 0; $i < $count; $i++) {
        $str = str_replace($u[$i], $u1[$i], $str);
    }
//    $str = str_replace($u, 'u', $str);
    $count = count($d);
    for ($i = 0; $i < $count; $i++) {
        $str = str_replace($d[$i], $d1[$i], $str);
    }
//    $str = str_replace($d, 'd', $str);
     $count = count($ii);
    for ($i = 0; $i < $count; $i++) {
        $str = str_replace($ii[$i], $ii1[$i], $str);
    }
//    $str = str_replace($i, 'i', $str);
    $count = count($y);
    for ($i = 0; $i < $count; $i++) {
        $str = str_replace($y[$i], $y1[$i], $str);
    }
    //$str = str_replace($y, 'y', $str);
    $count = count($d);
    for ($i = 0; $i < $count; $i++) {
        $str = str_replace($d[$i], $d1[$i], $str);
    }
    //$str = str_replace($d, 'd', $str);
    $str = strtolower($str);
    return $str;
}

Không có nhận xét nào:

Đăng nhận xét