简体   繁体   中英

How to force characters to be in a certain Upper or lower case sensitive format?

I have a simple search bar for a user to search any name in a database.

$name = $_POST['name'];

And so whenever a user inputs the name I output

<h1> You have searched <?php print( "$name" )?>'s name</h1>

What I need is that for example if a user types, "leOnARD" for some reason, I would like it to come out as "Leonard" rather than "leOnARD".

ucfirst()strtolower()似乎是您想要的。

echo ucfirst(strtolower("leOnARD")); // prints Leonard

Use the ucfirst() function in PHP. It will capitalize the first letter of your word.

ucfirst(strtolower($name));

这将降低除首字母之外的所有内容。

使用以下内容:

<h1> You have searched <?php print ucfirst(strtolower( "$name" )) ?>'s name</h1>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM