englishtokorea/web/app/Helpers/word_helper.php
2025-05-28 14:26:49 +09:00

75 lines
2.5 KiB
PHP

<?php
if (!function_exists('get_word_class_badge')) {
function get_word_class_badge($word_class)
{
// 배지 색상을 정의합니다.
$colors = [
"명사" => "custom-orange",
"동사" => "custom-purple",
"형용사" => "custom-teal",
"부사" => "custom-cerulean",
"전치사" => "custom-amethyst",
"대명사" => "custom-amber",
"약어" => "custom-lavender",
"접두사" => "custom-coral",
"감탄사" => "custom-sapphire",
"한정사, 대명사" => "custom-ruby",
"법조동사" => "custom-turquoise",
"접속사" => "custom-emerald",
"한정사" => "custom-rose",
"접미사" => "custom-periwinkle",
"복합형" => "custom-peach",
"수사" => "custom-lime",
"명사(약어)" => "custom-ivory",
"단축형" => "custom-gold",
"형용사, 부사" => "custom-silver",
"대명사, 형용사" => "custom-bronze",
"대명사, 한정사" => "custom-cyan",
"조동사" => "custom-magenta",
"부사, 전치사" => "custom-chartreuse",
"축약형" => "custom-indigo",
"" => "custom-olive",
null => "custom-olive",
];
// 기본 색상 설정
$badge_color = isset($colors[$word_class]) ? $colors[$word_class] : "custom-olive";
// 배지 HTML 반환
return "<span class='badge text-bg-$badge_color'>$word_class</span>";
}
if (!function_exists('split_by_is_first_row')) {
function split_by_is_first_row($data)
{
$first_row = [];
$second_row = [];
foreach ($data as $item) {
if ($item['is_first_row'] == 1) {
$first_row[] = $item;
} else {
$second_row[] = $item;
}
}
return [$first_row, $second_row];
}
}
if (!function_exists('keep_korean')) {
function keep_korean($text) {
// 정규 표현식을 사용하여 한글만 남기고 나머지 문자 제거
return preg_replace('/[^가-힣]/u', '', $text);
}
}
if (!function_exists('keep_english')) {
function keep_english($text) {
// 정규 표현식을 사용하여 영어만 남기고 나머지 문자 제거
return preg_replace('/[^a-zA-Z]/', '', $text);
}
}
}