用 PHP 删除字符串的前 4 个字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4286423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:31:52 来源:igfitidea点击:
Remove first 4 characters of a string with PHP
提问by Belgin Fish
How can I remove the first 4 characters of a string using PHP?
如何使用 PHP 删除字符串的前 4 个字符?
回答by Daniel Vandersluis
回答by Gumbo
回答by Eng Hany Atwa
function String2Stars($string='',$first=0,$last=0,$rep='*'){
$begin = substr($string,0,$first);
$middle = str_repeat($rep,strlen(substr($string,$first,$last)));
$end = substr($string,$last);
$stars = $begin.$middle.$end;
return $stars;
}
example
例子
$string = 'abcdefghijklmnopqrstuvwxyz';
echo String2Stars($string,5,-5); // abcde****************vwxyz
回答by Tarun modi
You could use the substr
function please check following example,
您可以使用该substr
功能,请检查以下示例,
$string1 = "tarunmodi";
$first4 = substr($string1, 4);
echo $first4;
Output: nmodi
回答by Sathish Kumar
$num = "+918883967576";
$str = substr($num, 3);
echo $str;
Output:8883967576
输出:8883967576
回答by Rejneesh Raghunath
回答by Obaidul Haque
You can use this by php function with substr function
您可以通过带有 substr 函数的 php 函数使用它
<?php
function removeChar($value) {
$value2 = substr($value, 4);
return $value2;
}
echo removeChar("Dummy Text. Sample Text.");
?>
You get this result: " y Text. Sample Text."
你会得到这样的结果:“ y 文本。示例文本。”