字符串数组如果字符串长度是> = = 6那么我想用*符号替换字符串前3和后3个字符。?如果字符串长度是< 5输出应小于6个字符。
$strings=array("johndoee","shawnmarsh","peterparker","johndoee","shawnmarsh","peterparker","abcde","qwert");
答案 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);
}
}