다음과 같은 slugify 메소드를 사용하고 있습니다. 내 프로덕션 서버 (CentOS) 및 PCRE UTF8에서 지원되지만 "유니 코드 속성 없음"이 지원됩니다.preg_replace()를 사용하지 않고 PHP 슬러그 메소드
function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
// trim
$text = trim($text, '-');
// transliterate
if (function_exists('iconv')) {
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
}
// lowercase
$text = strtolower($text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
if (empty($text)) {
return 'n-a';
}
return $text;
}
preg_replace이다가 작동하지 않는 경우, preg_replace이다 또는 상기 함수로서 작동 할 수있는 slugify muthod로 동작 할 수있는 방법이있다.
미리 감사드립니다.
us-ascii로 변환 한 경우 UTF8 지원이 필요한 이유는 무엇입니까? "작동하지 않음"을 정의하십시오. –
왜 투표가 취소 되었습니까? – Atticus
유니 코드 속성 지원이 실제로 필요합니다. – mushfiq