简体   繁体   中英

PHP function that translates, e.g., "æ" into "ae" and vice versa?

是否有 PHP 函数可以将“Æ”等连字转换为“AE”,反之亦然

You could use one of a few of PHP's functions, one being the preg_replace() function.

<?php

$replace='Æ';
$new=str_replace('Æ', 'AE', $replace); 

echo $new;

Will echo AE


Vice-versa would be:

<?php

$replace='AE';
$new=str_replace('AE', 'Æ', $replace); 

echo $new;

Will echo Æ


Using the str_replace() function, it can be used in sentences, such as:

echo str_replace("Æ","AE","Æ has been replaced from using: ") . "Æ";

Which will echo AE has been replaced from using: Æ

iconv with " //TRANSLIT " works very well:

$strWithoutLigatures = iconv("utf-8", "us-ascii//TRANSLIT", $strWithLigatures);

( source )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM