Home  >  Article  >  Backend Development  >  How to convert the first letter of a string to uppercase in php

How to convert the first letter of a string to uppercase in php

怪我咯
怪我咯Original
2017-07-06 10:50:401546browse

This article mainly introduces the method of converting the first letter of string into uppercase in php, involving the ucfirst and ucwords functions in php usage tips, friends in need can refer to

The example of this article describes the method of converting the first letter of a string into uppercase in PHP. Share it with everyone for your reference. The specific analysis is as follows:

In PHP, you can use the ucfirst function to convert the first letter in a string to uppercase, and the ucwords function can convert the first letter of each word in a string to uppercase

<?php
$string = "php string functions are easy to use.";
$sentence = ucfirst($string);
$title = ucwords($string);
print("$sentence\n");
print("$title\n");
print("\n");
?>

The output results are as follows:

Php string functions are easy to use.
Php String Functions Are Easy To Use

The above is the detailed content of How to convert the first letter of a string to uppercase in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn