ucfirst()는 각 문자열의 첫 번째 문자를 소문자에서 대문자로 변환하는 데 사용되는 PHP의 사전 정의된 함수입니다. 문자열을 입력으로 사용하고 문자가 알파벳인 경우 문자열의 첫 번째 문자를 대문자로 사용하여 동일한 결과를 반환합니다.
무료 소프트웨어 개발 과정 시작
웹 개발, 프로그래밍 언어, 소프트웨어 테스팅 등
이 "알파벳"은 현재 로케일에 따라 결정됩니다. ucfirst()와 유사한 ucwords()도 있습니다. 여기에 사용된 문자열은 구분 기호 매개변수(공백, 개행, 가로 탭, 세로 탭 등) 바로 뒤에 나열되는 많은 문자 모음인 단어입니다. 🎜>
구문:
ucfirst(string<em> $str)</em>
전달된 $string 인수에서 첫 번째 문자만 대문자로 수정하여 정확한 문자열을 반환합니다.
PHP ucfirst()의 예
예시 #1
코드:
<?php // This is an example of PHP code which // shows the functioning of ucfirst $string = "example for ucfirst"; // converts the string assigned to $string to uppercase // and displays the output echo(ucfirst($string)); ?>
출력:
예
코드:
<?php // This is an example of a PHP program which // shows how the ucfirst works when // the string having first case already in upper case $string = "Just an example"; // Since the first case is already upper case // it displays exact same in output echo(ucfirst($string)); ?>
출력:
예시 #3
코드:
<?php //This is an example of PHP code which //shows how to use ucfirst function for 2 //or more strings $str1 = "this is first string"; //declaration of first string echo ucfirst($str1); echo "\n"; $str2 = "this is second string"; //declaration of first string echo ucfirst($str2); ?>
출력:
예시 #4
코드:
<?php $str1 = 'example for hello world!'; $str1 = ucfirst($str1); echo($str1); echo("\n"); $str2 = 'EXAMPLE FOR HELLO WORLD!'; $str2 = ucfirst($str2); echo($str2); echo("\n"); //use of strtolower() function $str2 = ucfirst(strtolower($str2)); echo($str2); echo("\n"); //use of lcfirst() function $str2 = lcfirst($str2); echo($str2); ?>
출력:
이는 lcfirst, strtolower 등과 같은 다른 함수를 ucfirst 함수와 함께 사용하여 원하는 문자열 출력을 얻을 수 있음을 보여줍니다. 또한 $str1과 $str2라는 두 문자열의 사용법과 동일한 문자열 매개변수를 다른 함수에 전달하는 방법도 보여줍니다.
결론
위 내용은 PHP ucfirst()의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!