Home  >  Article  >  Backend Development  >  Let’s bring trouble to the first character of the string!

Let’s bring trouble to the first character of the string!

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-08-03 17:28:171910browse

In the previous article, we learned about the method of converting characters into HTML entities. If necessary, please read "How Characters Become HTML Entities Through Functions". This time we will introduce to you how to change the case of the first character of a string. You can refer to it if you need it.

We all know that the first character of a string has only two possibilities: uppercase and lowercase. The only thing that can change is changing the thank you of the first character to lowercase, or changing the lowercase of the first character to uppercase. First, let's introduce how to convert the first character of a string to lowercase.

Let’s look at a small example.

<?php
echo lcfirst("Hello world!");
?>

The result is

Let’s bring trouble to the first character of the string!

In this example, we can see that when we use the lcfirst function we can convert the first character into lowercase.

Now that we have a certain understanding of this function, let’s take a look at this function in detail to have a better understanding of this function.

The syntax of this function is

lcfirst(要转换的字符串)

La la la, we should know how to convert the first character to lowercase, now let’s take a look at how to convert the first character to uppercase, just want to Damn this string.

Of course, let’s look at a small example first.

<?php
echo ucfirst("hello world!");
?>

The result is

Let’s bring trouble to the first character of the string!

In this small example, you can see that the effect of this function is exactly the opposite of the previous function. The previous one will string The first character of is lowercase. Now the first character of the string is uppercase.

Now that we have learned this, let’s take a look at the syntax of this function.

ucfirst(要转换的字符串)

Of course, these two functions can only convert the first letter of the first word in the string to upper and lower cases, and there is no way to convert each word to upper and lower cases. If you want to convert the case of each word, the functions you need to use are strtoupper() and strtolower(). But I won’t introduce it in each article.

That’s all. If you want to know anything else, you can click here. → →php video tutorial

The above is the detailed content of Let’s bring trouble to the first character of the string!. 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