Files
zyt/server/app/common/service/doctor/MedicineNameAbbrService.php
T
2026-03-27 18:06:12 +08:00

26 lines
566 B
PHP

<?php
namespace app\common\service\doctor;
use Overtrue\Pinyin\Pinyin;
/**
* 药材名称 → 拼音首字母连写(小写),供列表检索;未安装 overtrue/pinyin 时返回空字符串。
*/
class MedicineNameAbbrService
{
public static function build(string $name): string
{
$name = trim($name);
if ($name === '') {
return '';
}
if (!class_exists(Pinyin::class)) {
return '';
}
$abbr = (string) Pinyin::abbr($name)->join('');
return strtolower($abbr);
}
}