首页 > 解决方案 > How to display only part of a string using PHP/html/java?

问题描述

Usernames on my website are all stored in a form like this "steve.jones" or "lisa-ann.smith", and referred to in my code as only $login (string).

Is there any way i can display only the first name on a site, and changing the first letter to capital?

thanks in advance

标签: phpstring

解决方案


在PHP中,你可以使用以“.”分隔的explode函数,然后使用ucfirst函数将其转换为首字母大写

<?php
$login = "steve.jones";
$firstname = explode(".", $login);
$firstname[0] = ucfirst($firstname[0]);
echo $firstname[0];
?>

推荐阅读