用php封装一个手机号脱敏的函数
时间: 2023-03-10 08:06:07 浏览: 58
答:可以使用以下php函数来封装一个手机号脱敏的函数:<?php function mask_phone($phone) { return substr($phone, 0, 3) . '****' . substr($phone, -4); } ?>
相关问题
用php封装一个验证账号格式是否正确的函数
可以使用正则表达式来验证账号格式是否正确,以下是一个简单的示例:
```php
function validateAccount($account) {
// 账号格式正则表达式,这里以字母开头,只包含字母、数字和下划线,长度为6到20位为例
$pattern = '/^[a-zA-Z][a-zA-Z0-9_]{5,19}$/';
return preg_match($pattern, $account);
}
```
这个函数接受一个账号参数,使用正则表达式进行验证,如果账号符合要求返回 true,否则返回 false。你可以根据实际需要修改正则表达式的规则来适应不同的账号格式要求。
封装一个php curl post请求函数
以下是一个基本的封装curl post请求函数的示例:
```
function http_post($url, $params) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
```
这个函数的参数包括一个URL和一个参数数组。它使用curl库的POST请求来发送参数到指定的URL,并返回响应。在这个例子中,我们使用`http_build_query()`函数将参数数组转换为URL编码的字符串,并将其作为POST请求的主体。