用口音替换口音 [英] Replacing accents with their counterparts

查看:110
本文介绍了用口音替换口音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因(这是一个很长的故事),我需要用他们的正常同行更改口音。

For some reason (it's a long story) I need to change the accents with their 'normal' counterparts.

我这样做:

$array = array(
            'ò' => 'o',
            'ó' => 'o',
            'à' => 'a',
            'è' => 'e',
            'é' => 'e',
            'ù' => 'u',
            );
return str_replace(array_keys($array), array_values($array), $string);

但它不起作用(正常字母的作品就像一个魅力)我认为这是一个编码问题是否有另一种方法呢?如何解决这个问题?

but it doesn't work (with normal letter works like a charm) I think it's an encoding problem, is there another way to do this? How can I fix this?

谢谢。

推荐答案

PHP中的URL友好用户名,稍作修改

function Slug($string)
{
    return strtolower(trim(preg_replace('~[^0-9a-z]+~i', '-', preg_replace('~&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', htmlentities($string, ENT_QUOTES, 'UTF-8'))), ' '));
}

$user = 'Alix Axel';
echo Slug($user); // alix axel

$user = 'Álix Ãxel';
echo Slug($user); // alix axel

$user = 'Álix----_Ãxel!?!?';
echo Slug($user); // alix axel

这篇关于用口音替换口音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆