php - How to Hiding Seconds Word Chars [PHP]
问题描述
If string has more than one word
Example String: AAAAAA BBBBB CCCCCCC
Output: AAAAAA BB*** CCCC***
If string has one word do nothing
Example String: AAAAAA
Output: AAAAAA
I need to hide every last 3 chars of words if string has more than two word. I tried str_replace but I can't make it. Thanks for help
解决方案
我相信,这对你有用。
<?php
$input = "AAAA B";
$words = explode(" ", $input);
for($i = 1; $i < count($words); $i++) {
$words[$i] = substr($words[$i], 0, -3) . "***";
}
$output = implode(" ", $words);
echo $output;
?>
但请记住,如果您的单词少于 3 个字母,它们将被替换为***
.
推荐阅读
- java - 如何调试错误“字符串资源 ID #0x0”
- gradle - Gradle 任务部署(类型:exec)
- html - 我如何限制在文本框中为 html 中的 div 元素输入的字符数
- javascript - 我正在尝试使用 JSPDF 将整个页面下载为 PDF,但是生成的 PDF 文件中的文本超出了页面
- javascript - Django:在模板中导入 javascript 不起作用
- c# - 如何发送具有新更改值的变量 c# mvc 或如何按名称杀死线程?
- entity-framework - 实体框架迁移错误地检测为待处理
- c# - 为什么 Range.End 没有改变?
- model - 如何从 .Net 代码建模一些 OPC UA 类
- cocoa - 带有值绑定的 NSTextView 上的段落样式未更新