php 截取函数
使用时,参考注释
function str_replace_fuc($string, $bengin = 0, $len = 4, $type = 0, $glue = "@") {
if (empty($string))
return false;
$array = array();
if ($type == 0 || $type == 1 || $type == 4) {
$strlen = $length = mb_strlen($string);
while ($strlen) {
$array[] = mb_substr($string, 0, 1, "utf8");
$string = mb_substr($string, 1, $strlen, "utf8");
$strlen = mb_strlen($string);
}
}
if ($type == 0) {
for ($i = $bengin; $i < ($bengin + $len); $i++) {
if (isset($array[$i]))
$array[$i] = "*";
}
$string = implode("", $array);
} else if ($type == 1) {
$array = array_reverse($array);
for ($i = $bengin; $i < ($bengin + $len); $i++) {
if (isset($array[$i]))
$array[$i] = "*";
}
$string = implode("", array_reverse($array));
} else if ($type == 2) {
$array = explode($glue, $string);
$array[0] = hideStr($array[0], $bengin, $len, 1);
$string = implode($glue, $array);
} else if ($type == 3) {
$array = explode($glue, $string);
$array[1] = hideStr($array[1], $bengin, $len, 0);
$string = implode($glue, $array);
} else if ($type == 4) {
$left = $bengin;
$right = $len;
$tem = array();
for ($i = 0; $i < ($length - $right); $i++) {
if (isset($array[$i]))
$tem[] = $i >= $left ? "*" : $array[$i];
}
$array = array_chunk(array_reverse($array), $right);
$array = array_reverse($array[0]);
for ($i = 0; $i < $right; $i++) {
$tem[] = $array[$i];
}
$string = implode("", $tem);
}
return $string;
}