php - 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
解决方案
在PHP中,你可以使用以“.”分隔的explode函数,然后使用ucfirst函数将其转换为首字母大写
<?php
$login = "steve.jones";
$firstname = explode(".", $login);
$firstname[0] = ucfirst($firstname[0]);
echo $firstname[0];
?>
推荐阅读
- python - 为舍入设置明确限制
- css - 修复 inline-flex 强制 TD 有双边框
- amazon-web-services - AWS API Gateway HttpAPI SAM 自定义域名错误
- google-bigquery - 从转换的 lon 和 lat 数据到 geojson 缺少“类型”:特征、“几何”
- node.js - GroupBy 聚合,包括 mongo 中的缺失日期
- sql - 加入3个表不正确的结果
- c# - 如何使用自动映射器添加现有实体而不从上下文中获取它而不会在 ef 核心中违反主键
- powershell - PowerShell:无法过滤通用列表的特殊情况
- c++ - 我的程序在执行期间找不到我的共享库
- sql - 选择主要电话号码(如果存在),否则使用 SQL 选择最新的电话号码一