1,获取用户首字母
public function getFirstCharter($str)
{
if (empty($str)) {
return '';
}
$fchar = ord($str{0});
if ($fchar >= ord('A') && $fchar <= ord('z')) return strtoupper($str{0});
$s1 = iconv('UTF-8//IGNORE', 'GBK//IGNORE', $str);
$s2 = iconv('GBK//IGNORE', 'UTF-8//IGNORE', $s1);
$s = $s2 == $str ? $s1 : $str;
$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
if ($asc >= -20319 && $asc <= -20284) return 'A';
if ($asc >= -20283 && $asc <= -19776) return 'B';
if ($asc >= -19775 && $asc <= -19219) return 'C';
if ($asc >= -19218 && $asc <= -18711) return 'D';
if ($asc >= -18710 && $asc <= -18527) return 'E';
if ($asc >= -18526 && $asc <= -18240) return 'F';
if ($asc >= -18239 && $asc <= -17923) return 'G';
if ($asc >= -17922 && $asc <= -17418) return 'H';
if ($asc >= -17417 && $asc <= -16475) return 'J';
if ($asc >= -16474 && $asc <= -16213) return 'K';
if ($asc >= -16212 && $asc <= -15641) return 'L';
if ($asc >= -15640 && $asc <= -15166) return 'M';
if ($asc >= -15165 && $asc <= -14923) return 'N';
if ($asc >= -14922 && $asc <= -14915) return 'O';
if ($asc >= -14914 && $asc <= -14631) return 'P';
if ($asc >= -14630 && $asc <= -14150) return 'Q';
if ($asc >= -14149 && $asc <= -14091) return 'R';
if ($asc >= -14090 && $asc <= -13319) return 'S';
if ($asc >= -13318 && $asc <= -12839) return 'T';
if ($asc >= -12838 && $asc <= -12557) return 'W';
if ($asc >= -12556 && $asc <= -11848) return 'X';
if ($asc >= -11847 && $asc <= -11056) return 'Y';
if ($asc >= -11055 && $asc <= -10247) return 'Z';
return null;
}
2,过滤敏感词
/*
* 过滤敏感词
* $str
* return $str
*/
public function FilterWorde($str)
{
if ( !($words = file_get_contents( "../public/word/key.txt" )) ){
die('file read error!');
}
// $word = preg_replace("/[1,2,3]\r\n|\r\n/i", '', $words);
$arr = explode("|",$words);
for($i=0;$i<count($arr);$i++)
{
// $str = preg_replace('/'.$arr[$i].'/i', '***', $str);
$str = str_replace($arr[$i], '***', $str);
}
return $str;
}
3,输入内容有表情,如昵称的解码和转码
function userTextEncode($str){
if(!is_string($str))return $str;
if(!$str || $str=='undefined')return '';
$text = json_encode($str);
$text = preg_replace_callback("/(\\\u[ed][0-9a-f]{3})/i",function($str){
return addslashes($str[0]);
},$text);
return json_decode($text);
}
function userTextDecode($str){
$text = json_encode($str);
$text = preg_replace_callback('/\\\\\\\\/i',function($str){
return '\\';
},$text);
return json_decode($text);
}
4,curl访问(包含https)
public function getInfo($url,$data)
{
$ch = curl_init ();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
$result = curl_exec ( $ch );
curl_close ( $ch );
return json_decode($result,true);
}
public function getInfo($url,$data,$type)
{
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
if ($type)
{
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
}
$result = curl_exec ( $ch );
curl_close ( $ch );
return json_decode($result,true);
}
5,H5 js桥接交互
function setupWebViewJavascriptBridge(callback) {
if (window.WebViewJavascriptBridge) {
return callback(WebViewJavascriptBridge);
}
if (window.WVJBCallbacks) {
return window.WVJBCallbacks.push(callback);
}
window.WVJBCallbacks = [callback];
var WVJBIframe = document.createElement('iframe');
WVJBIframe.style.display = 'none';
WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
document.documentElement.appendChild(WVJBIframe);
setTimeout(function () {
document.documentElement.removeChild(WVJBIframe)
}, 0)
}
setupWebViewJavascriptBridge(function (bridge) {
bridge.registerHandler('myron', function (data, response) {
x = document.getElementById("kword");
response('success');
});
u = navigator.userAgent;
isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
function keyword(data) {
var item = encodeURI(data);
if (isiOS) {
WebViewJavascriptBridge.callHandler('getKeyWord', {
'key': item
}, function responseCallback(responseData) {
})
} else {
andrkey(data)
}
}
function andrkey(data) {
android.getKeyWord(data);
}
6,查询添加链接
$mlMembers=Db::name('user_detail')
->alias('ud')
->join('mechanism_user mu','mu.mu_ub_id=ud.ud_ub_id')
->field(["ud.ud_name",'ud.ud_ub_id','ud.ud_nickname','ud.ud_sex','concat("'.WEB_URL.'","",ud_photo)'=>'ud_photo','ud.ud_detail','mu.mu_type','mu.mu_ml_id'])
->where('mu_ml_id',$ml_id)
->where('mu_ub_id','<>',$ub_id)
->select();
7,AJAX