
PHP의 mb_strtolower 함수는 문자열 전체를 소문자로 변환하는 함수입니다. 만약에 첫 번째 문자만 소문자로 변환하고 싶다면, 다음 코드를 사용할 수 있습니다.
#hostingforum.kr
php
$string = 'Hello World!';
echo mb_strtolower($string, 'UTF-8'); // hello world!
echo mb_strtolower(mb_substr($string, 0, 1), 'UTF-8') . mb_strtolower(substr($string, 1)); // hello world!
위의 두 번째 예제는 첫 번째 문자만 소문자로 변환하고 나머지 문자는 그대로 유지하는 방법입니다.
만약에 mb_lcfirst 함수를 사용해야 하는 상황이라면, PHP 8.1 이상 버전에서 사용할 수 있습니다.
#hostingforum.kr
php
$string = 'Hello World!';
echo mb_strtolower($string, 'UTF-8'); // hello world!
echo mb_lcfirst($string); // h
PHP 8.1 이상 버전에서 mb_lcfirst 함수를 사용하면 첫 번째 문자만 소문자로 변환할 수 있습니다.
2025-03-19 15:52