如何通过PHP将SELECT datepart(ww,[Promised Ship Date]) as weekno
,[Item ID]
,[UNITOFMEASURE]
,[UNITOFMEASURECONV] as ConvQTY
,count(*) as Orders
FROM SalesHistory vw
inner join ITEMTABLE IT on IT.itemcode = vw.[Item Id]
where [Promised Ship Date] >= '2016-01-01' and [Promised Ship Date] < '2016-02-01'
and [UDF_MIN_SALES_UNIT] = 'Each'
group by datepart(ww,[Promised Ship Date]),[item id],[unitofmeasure],[UNITOFMEASURECONV]
order by weekno,[item id]
替换为<%= text_field_tag :email, nil, placeholder: 'Email' %>
来显示和隐藏一些电话号码?
EX:
09350943256 - &gt; 0935 *** 3256
09119822432 - &gt; 0911 *** 2432
09215421597 - &gt; 0921 *** 1597
...
*
热门PHP代码的结果如下:0935***3256
但我希望结果为:$number = '09350943256';
echo str_pad(substr($number, -4), strlen($number), '*', STR_PAD_LEFT);
怎么回事?
答案 0 :(得分:3)
你可以这样使用substr和concat
假设您的$ number是12位数
echo substr($number, 0, 4) . '****' . substr($number, -4);
答案 1 :(得分:2)
简而言之:
$phone = 01133597084;
$maskedPhone = substr($user->phone, 0, 4) . "****" . substr($user->phone, 7, 4);
<块引用>
// $maskedPhone 的输出是 0113****7084
答案 2 :(得分:0)
您可以使用substr()
来获取前4个和后4个,并在中间手动添加4个*
,并将它们全部放在一个字符串中。
$phone = "09350943256";
$result = substr($phone, 0, 4);
$result .= "****";
$result .= substr($phone, 7, 4);
echo $result;
上面会输出
0935 **** 3256
答案 3 :(得分:0)
<?php
$phone='05325225990';
function stars($phone)
{
$times=strlen(trim(substr($phone,4,5)));
$star='';
for ($i=0; $i <$times ; $i++) {
$star.='*';
}
return $star;
}
$result=str_replace(substr($phone, 4,5), stars($phone), $phone);
echo $result;
?>
0532 ***** 90
答案 4 :(得分:0)
您可以使用substr_replace()
功能
<?php
$mobnum ="09350943256";
for($i=4;$i<7;$i++)
{
$mobnum = substr_replace($mobnum,"*",$i,1);
}
echo $mobnum;
?>
答案 5 :(得分:0)
我建议使用这种“声明式”解决方案,而不是计算指数的数学运算:
<?php
$number='0123456789';
$matches=[];
preg_match('/(\\d{4})(\\d+)(\\d{4})/', $number, $matches);
$result=$matches[1].str_repeat('*',strlen($matches[2])).$matches[2];
print($result);
?>