<?php
class GetMacAddr{
var $return_array = array(); //
var $mac_addr;
function GetMacAddr($os_type){
switch ( strtolower($os_type) ){
case "linux":
$this->forLinux();
break;
case "solaris":
break;
case "unix":
break;
case "aix":
break;
default:
$this->forWindows();
break;
}
$temp_array = array();
foreach ( $this->return_array as $value ){
if (
preg_match("/[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f]/i",$value,
$temp_array ) ){
$this->mac_addr = $temp_array[0];
break;
}
}
unset($temp_array);
return $this->mac_addr;
}
function forWindows(){
@exec("ipconfig /all", $this->return_array);
if ( $this->return_array )
return $this->return_array;
else{
$ipconfig = $_SERVER["WINDIR"]."\system32\ipconfig.exe";
if ( is_file($ipconfig) )
@exec($ipconfig." /all", $this->return_array);
else
@exec($_SERVER["WINDIR"]."\system\ipconfig.exe /all", $this->return_array);
return $this->return_array;
}
}
function forLinux(){
@exec("ifconfig -a", $this->return_array);
return $this->return_array;
}
}
//·½·¨Ê¹ÓÃ
$mac = new GetMacAddr(PHP_OS);
echo $mac->mac_addr;
?>
function currencyToChinese($data)
{
$data = str_replace(',', '', $data);
if ($data == '') {
return '';
}
$prefix = '';
$cncap = '';
if ($data < 0) {
$prefix .= '负';
$data = substr($data, 1, strlen($data) - 1);
}
$capnum = array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖");
$capdigit = array("", "拾", "佰", "仟");
$subdata = explode(".", $data);
if (!isset($subdata[1])) {
$subdata[1] = 0;
}
if (intval($subdata[0]) == 0 && intval($subdata[1]) == 0) {
return $prefix . "零元整";
}
$yuan = $subdata[0];
$j = 0; $nonzero = 0;
for ($i = 0; $i < strlen($subdata[0]); $i++) {
if (0 == $i) { //确定个位
if (intval($subdata[1]) != 0) {
if (substr($subdata[0], -1, 1) == 0) {
$cncap .= "元零";
} else {
$cncap .= "元";
}
} else {
if (intval($subdata[0]) != 0) {
$cncap = "元";
}
}
}
if (4 == $i) {
$j = 0;
$nonzero = 0;
$cncap = "万" . $cncap;
} //确定万位
if (8 == $i) {
$j = 0;
$nonzero=0;
$cncap="亿" . $cncap;
} //确定亿位
$numb = substr($yuan, -1, 1); //截取尾数
$cncap = ($numb) ?
$capnum[$numb] . $capdigit[$j] . $cncap : (($nonzero)?"零" . $cncap : $cncap);
$nonzero = ($numb) ? 1 : $nonzero;
$yuan = substr($yuan, 0, strlen($yuan)-1); //截去尾数
$j++;
}
$chiao = '';
$cent = '';
if (intval($subdata[1]) != 0) {
$chiao = (substr($subdata[1], 0, 1)) ?
$capnum[substr($subdata[1], 0, 1)] . "角" : "零";
$cent = (substr($subdata[1], 1, 1)) ?
$capnum[substr($subdata[1], 1, 1)] . "分" : "零分";
}
$cncap .= $chiao.$cent;
if (substr($subdata[1], -1, 1) === '0') {
$cncap .= "整";
}
$cncap = preg_replace("/(零)+/", "\\1", $cncap); //合并连续“零”
if (intval($subdata[0]) == 0) {
$cncap = preg_replace("/(元零)+/", "", $cncap);
$cncap = preg_replace("/(元)+/", "", $cncap);
}
if (intval($subdata[1]) == 0 || substr($subdata[1], -1, 1) === '0') {
$cncap = preg_replace("/(零分)+/", "", $cncap);
}
return $prefix . $cncap;
}
<?php
function characet($data,$code='UTF-8'){
if( !empty($data) ){
$fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;
if( $fileType != $code){
$data = mb_convert_encoding($data ,$code, $fileType);
}
}
return $data;
}
?>
function getKeyValues($arr, $key)
{
$ret = [];
foreach ($arr as $row) {
if (is_array($row) && array_key_exists($key, $row)) {
$ret[] = $row[$key];
} elseif ($row instanceof \ArrayObject) {
$row->offsetExists($key) && $ret[] = $row->offsetGet($key);
}
}
return $ret;
}
/**
* 检测是否是手机访问
*/
function is_mobile()
{
$useragent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$useragent_commentsblock = preg_match('|\(.*?\)|', $useragent, $matches) > 0 ? $matches[0] : '';
function _is_mobile($substrs, $text)
{
foreach ($substrs as $substr)
if (false !== strpos($text, $substr)) {
return true;
}
return false;
}
$mobile_os_list = array('Google Wireless Transcoder', 'Windows CE', 'WindowsCE', 'Symbian', 'Android', 'armv6l', 'armv5', 'Mobile', 'CentOS', 'mowser', 'AvantGo', 'Opera Mobi', 'J2ME/MIDP', 'Smartphone', 'Go.Web', 'Palm', 'iPAQ');
$mobile_token_list = array('Profile/MIDP', 'Configuration/CLDC-', '160×160', '176×220', '240×240', '240×320', '320×240', 'UP.Browser', 'UP.Link', 'SymbianOS', 'PalmOS', 'PocketPC', 'SonyEricsson', 'Nokia', 'BlackBerry', 'Vodafone', 'BenQ', 'Novarra-Vision', 'Iris', 'NetFront', 'HTC_', 'Xda_', 'SAMSUNG-SGH', 'Wapaka', 'DoCoMo', 'iPhone', 'iPod');
$found_mobile = _is_mobile($mobile_os_list, $useragent_commentsblock) ||
_is_mobile($mobile_token_list, $useragent);
if ($found_mobile) {
return true;
} else {
return false;
}
}
//剔除a标签
function tichuA($str){
$str1 = preg_replace("/<a[^>]*>/","", $str);
$str2 = preg_replace("/<\/a>/","", $str1);
return $str2;
}
直接用 floatval($arg) 来转换,既可以保留有效的小数点,也可以去掉后面多余的0, 其中arg 为变量
$number1 = "98.00";
$number2 = "98.76";
echo floatval($number1); //输出结果:98
echo floatval($number2); //输出结果:98.76
/**
*
* curl 支持post
* @param string $base_url 基础链接
* @param array $query_data 需要请求的数据
* @param string $method 方法 get/post
* @param boolean $ssl 关闭ssl验证
* @param integer $exe_timeout 执行超时时间
* @param integer $conn_timeout 连接超时时间
* @param integer $dns_timeout dns超时时间
*/
function tx_curl($base_url, $query_data, $method = 'get', $ssl = true, $exe_timeout = 10, $conn_timeout = 10, $dns_timeout = 3600)
{
$ch = curl_init();
if ( $method == 'get' ) {
//method get
if ( ( !empty($query_data) )
&& ( is_array($query_data) )
){
$connect_symbol = (strpos($base_url, '?')) ? '&' : '?';
foreach($query_data as $key => $val) {
if ( is_array($val) ) {
$val = serialize($val);
}
$base_url .= $connect_symbol . $key . '=' . rawurlencode($val);
$connect_symbol = '&';
}
}
} else {
if ( ( !empty($query_data) )
&& ( is_array($query_data) )
){
foreach($query_data as $key => $val) {
if ( is_array($val) ) {
$query_data[$key] = serialize($val);
}
}
}
//method post
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_data);
}
curl_setopt($ch, CURLOPT_URL, $base_url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $conn_timeout);
curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, $dns_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $exe_timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
// 关闭ssl验证
if($ssl){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
$output = curl_exec($ch);
if ( $output === FALSE )
$output = '';
curl_close($ch);
return $output;
}