字符串数组如果字符串长度是> =到6那么我想用*符号替换字符串前3和后3字符。?

时间:2017-08-24 09:48:46

标签: php arrays string replace

字符串数组如果字符串长度是> = = 6那么我想用*符号替换字符串前3和后3个字符。?如果字符串长度是< 5输出应小于6个字符。

$strings=array("johndoee","shawnmarsh","peterparker","johndoee","shawnmarsh","peterparker","abcde","qwert");

1 个答案:

答案 0 :(得分:1)

试试这个

$strings = array("johndoee", "shawnmarsh", "peterparker", "johndoee", "shawnmarsh", "peterparker", "abcde", "qwert");

foreach($strings as $index => $str)
{
    if(strlen($str)>=6)
    {
        $temp_str = substr_replace($str, "*", 0,3);
        $strings[$index] = substr_replace($temp_str, "*", -3);
    }
}