php生成字符串随机码实现方法

 更新时间:2016年11月25日 17:33  点击:1268

$validcharacters = "abcdefghijklmnopqrstuxyvwzabcdefghijklmnopqrstuxyvwz+-*#&@!?";
$index = mt_rand(0, 10);
echo $index;

//看一款复杂一点的

$validcharacters = "abcdefghijklmnopqrstuxyvwzabcdefghijklmnopqrstuxyvwz+-*#&@!?";
$validcharnumber = strlen($validcharacters);
$index = mt_rand(0, $validcharnumber-1);
$randomcharacter = $validcharacters[$index];
echo $randomcharacter;

//实例二

$length = 5;
$result = "";
for ($i = 0; $i < $length; $i++) {   
 $index = mt_rand(0, $validcharnumber-1);   
 $result .= $validcharacters[$index];
}

//

function getrandomstring($length = 6) {   
 $validcharacters = "abcdefghijklmnopqrstuxyvwzabcdefghijklmnopqrstuxyvwz+-*#&@!?";   
 $validcharnumber = strlen($validcharacters);    
 $result = "";    
 for ($i = 0; $i < $length; $i++) {       
  $index = mt_rand(0, $validcharnumber - 1);       
  $result .= $validcharacters[$index];   
 }    
 return $result;
}
echo getrandomstring();

在很我的时候我们需要得到用户的真实IP地址,例如,日志记录,地理定位,将用户信息,网站数据分析等,其实获取IP地址很简单$_SERVER[\'REMOTE_ADDR\']就可以了。

//最简单的方法

$ip = $_server['remote_addr'];

//上面的方法只要使用了代理你就无法得到真实ip地址,下面有更详细的方法

echo "remote addr: " . $_server['remote_addr']."<br/>";
echo "x forward: " . $_server['http_x_forwarded_for']."<br/>";
echo "clien ip: " . $_server['http_client_ip']."<br/>";

//好了来看一个实例。

function getip() {   
 $ip = $_server['remote_addr'];    
 if (!empty($_server['http_client_ip'])) {       
  $ip = $_server['http_client_ip'];   
 } elseif (!empty($_server['http_x_forwarded_for'])) {       
  $ip = $_server['http_x_forwarded_for'];   
 }   
  return $ip;
}

/*
如果是是加密的代理是无法获取真实ip地址的。

php获取当前页面url地址及参数 要获取当前页面的完整地址我们要经过很多操作如HTTP或HTTPS php文件与路径 主机域名 查询参数最后就成了。

获取协议 - http
url的协议,可以读出在$ _server ['server_protocol']变量。
*/

echo $_server['server_protocol'];

/*
如果你检查值,可以发现,不只是http或https,但这样的字符串:http/1.1的

*/

$protocol = strpos(strtolower($_server['server_protocol']),'https')  === false ? 'http' : 'https';

/*
获取主机域名*/

$host = $_server['http_host'];

/*
利用$ _server['script_name']获取除域名外的php文件与路径

*/

$script = $_server['script_name'];


//获取?后面查询参数

$params = $_server['query_string'];


//方法二
$uri = $_server['request_uri'];

//下面来看一个完整的获取当前url实例

$protocol = strpos(strtolower($_server['server_protocol']),'https')   === false ? 'http' : 'https';
$host     = $_server['http_host'];
$script   = $_server['script_name'];
$params   = $_server['query_string'];
$currenturl = $protocol . '://' . $host . $script . '?' . $params;
echo $currenturl;

ajax只支持utf-8格式,不能支持gb2312编码格式,所以经常遇到gb2312的编码的程序使用ajax就出现乱码,刚找到一种解决方案是

服务器端传送的数据仍是gb2312编码,客户端用js将汉字转变成utf8编码显示在页面

方法一json
一,服务器端json数据用php教程的iconv函数转换:iconv('gb2312', 'utf8', "被转换字符串,输出到浏览器"); 
      客户端获取utf8数据,再转成gb2312:

function gb2utf8(data){//gb编码是,ie通过二进制码utf8->gbk转为中文 
     var glbencode = []; 
     gb2utf8_data = data; 
     execscript("gb2utf8_data = midb(gb2utf8_data, 1)", "vbscript"); 
     var t=escape(gb2utf8_data).replace(/%u/g,"").replace(/(.{2})(.{2})/g|>,"%$2%$1").replace(/%([a-z].)%(.{2})/g|>,"@$1$2"); 
     t=t.split("@"); 
     var i=0,j=t.length,k; 
     while(++i<j)> 
         k=t.substring(0,4); 
         if(!glbencode[k]) { 
             gb2utf8_char = eval("0x"+k); 
             execscript("gb2utf8_char = chr(gb2utf8_char)", "vbscript"); 
             glbencode[k]=escape(gb2utf8_char).substring(1,6); 
         } 
         t=glbencode[k]+t.substring(4); 
     } 
     gb2utf8_data = gb2utf8_char = null; 
     return unescape(t.join("%")); 
}

二,header("content-type", "application/x-www-form-urlencoded; charset=gbk"); //输出头标,设置为gbk编码

三,在ajax请求数据前调用上面的方法指定请求使用的字符集:xmlhttp.setrequestheader( "content-type", "application/x-www-form-urlencoded;charset=gbk");


方案二
search.php

<?php
header("content-type: text/html; charset=gb2312");
include './search.htm';
?>

search.htm

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>高级搜索</title>
</head>
<body>
<h3>高级搜索</h3>
<form method="post" action="">
  学校类型:
  <select name="schooltype">
    <option value="">全部</option>
    <option value="1">小学</option>
    <option value="2">初中</option>
  </select>
  学校名称:
  <select name="sid" id="sid">
    <option value="">请选择学校</option>
  </select>
</form>
<script type="text/网页特效">
function ajax(settings) {
    var xhr = window.activexobject ? new activexobject("microsoft.xmlhttp") : new xmlhttprequest(), successed = false;
    xhr.open(settings.type, settings.url);
    if(settings.type == 'post')
     xhr.setrequestheader('content-type', 'application/x-www-form-urlencoded');
    xhr.send((!settings.cache ? 'time=' + new date().gettime() + '&' : '') + settings.data);
    settings.loader();
    settimeout(function() {
        if(!successed) {
            alert('resquest timeout!');
            xhr.abort();
        }
    }, settings.timeout);
    xhr.onreadystatechange = function() {
        if (xhr.readystate == 4 && xhr.status == 200) {
            settings.callback(xhr.responsetext.replace(/(^s*)|(s*$)/g, ""));
        }
        successed = true;
    }
}
function a(t) {
ajax({
  type: 'post',
  url: 'ajax.php',
  data: 'schooltype=' + t,
  timeout: 8000,
  cache: true,
  loader: function() {},
  callback: function(d) {
   var arr = eval(d);
   if(typeof(arr) == 'object') {
    var obj, option;
    document.getelementbyid('sid').innerhtml = '';
    for(var i = 0; obj = arr; i ++) {
     option = document.createelement('option');
     option.value = obj[0];
     option.innerhtml = txt2utf8(obj[1], '&#');
     document.getelementbyid('sid').appendchild(option);
    }
   }
  }
})
}
function txt2utf8(string, prefix){
    for(var i=0,utf8=[];i<string.length;utf8.push((prefix||'u')+string.charcodeat(i++)));
    return utf8.join('');
}
a(0);
</script>
</body>
</html>

ajax.php
<?php
header("content-type: text/html; charset=gb2312");
$schooltype = !empty($_post['schooltype']) ? $_post['schooltype'] : 0;
switch($schooltype) {
    case 0:
        echo "[['40', '太平溪镇花栗包完全小学'],['41', '太平溪镇长岭黑龙江希望小学'],['42', '乐天溪镇初级中学'],['43', '乐天溪镇莲沱初级中学']]";
        break;
    case 1:
        echo "[['40', '太平溪镇花栗包完全小学'],['41', '太平溪镇长岭黑龙江希望小学']]";
        break;
    case 2:
        echo "[['42', '乐天溪镇初级中学'],['43', '乐天溪镇莲沱初级中学']]";
        break;
    default:
        break;
}
?>

<?php教程
/*
 * 模板分页类,源于easp教程的数据库教程分页方法,算是easp分页的的php独立版
 * 支持动态和静态分页方式
 * * page([总记录数=1],[分页大小=20],[当前页=1],[显示页数=6],[分页参数='page'],[分页链接=当前页面],[是否静态=false])
 * 动态:
 * 简单用法:
 * $page = new page(50);
 * $page->setpager('zjj','<div class="newpager">共有{recordcount} 个商品&nbsp;&nbsp;当前第&nbsp;{pageindex}&nbsp;页&nbsp;/&nbsp;共&nbsp;{pagecount}&nbsp;页&nbsp;分页:&nbsp;{first}{prev}&nbsp;&nbsp;{list}&nbsp;&nbsp;{next}{last}&nbsp;&nbsp;转到&nbsp;{jump}&nbsp;页</div>',array("listlong"=>"6","first"=>"首页","last"=>"尾页","prev"=>"上一页","next"=>"下一页","list"=>"第*页","jump"=>"select"));
 * echo $page->getpager('zjj');
 * 全参数用法:
 * $page = new page(50,20,1,6,'page','prrr.php',false);
 * $page->setpager('zjj','<div class="newpager">共有{recordcount} 个商品&nbsp;&nbsp;当前第&nbsp;{pageindex}&nbsp;页&nbsp;/&nbsp;共&nbsp;{pagecount}&nbsp;页&nbsp;分页:&nbsp;{first}{prev}&nbsp;&nbsp;{list}&nbsp;&nbsp;{next}{last}&nbsp;&nbsp;转到&nbsp;{jump}&nbsp;页</div>',array("listlong"=>"6","first"=>"首页","last"=>"尾页","prev"=>"上一页","next"=>"下一页","list"=>"第*页","jump"=>"select"));
 * echo $page->getpager('zjj');
 * 静态:
 * $page = new page(50,20,1,6,'page','prrr{page}.html',true);
 * $page->setpager('zjj','<div class="newpager">共有{recordcount} 个商品&nbsp;&nbsp;当前第&nbsp;{pageindex}&nbsp;页&nbsp;/&nbsp;共&nbsp;{pagecount}&nbsp;页&nbsp;分页:&nbsp;{first}{prev}&nbsp;&nbsp;{list}&nbsp;&nbsp;{next}{last}&nbsp;&nbsp;转到&nbsp;{jump}&nbsp;页</div>',array("listlong"=>"6","first"=>"首页","last"=>"尾页","prev"=>"上一页","next"=>"下一页","list"=>"第*页","jump"=>"select"));
 * echo $page->getpager('zjj');
 */
class page {
 private $page_size; //每页显示的条目数
 private $total_size; //总条目数
 private $current_page; //当前被选中的页
 private $sub_pages; //每次显示的页数
 private $total_pages; //总页数
 private $page_tpl = array (); // 分页模板
 private $pageparam;
 private $pagelink;
 private $static;
 
 function __construct($total_size = 1, $page_size = 20, $current_page = 1, $sub_pages = 6, $pageparam = 'page', $pagelink = '', $static = false) {
  $this->page_size = intval ( $page_size );
  $this->total_size = intval ( $total_size );
  if (! $current_page) {
   $this->current_page = 1;
  } else {
   $this->current_page = intval ( $current_page );
  }
  $this->total_pages = ceil ( $total_size / $page_size );
  $this->sub_pages = intval ( $sub_pages );
  $this->pageparam = $pageparam;
  $this->pagelink = (empty ( $pagelink ) ? $_server ["php_self"] : $pagelink);
  $this->static = $static;
  $this->page_tpl ['default'] = array ('tpl' => '<div class="pager">{first}{prev}{liststart}{list}{listend}{next}{last} 跳转到{jump}页</div>', 'config' => array () );
 
 }
 public function __set($param, $value) {
  $this->$param = $value;
 }
 public function __get($param) {
  return $this->$param;
 }
 /*
  __destruct析构函数,当类不在使用的时候调用,该函数用来释放资源。
 */
 function __destruct() {
  unset ( $page_size ); //每页显示的条目数
  unset ( $total_size ); //总条目数
  unset ( $current_page ); //当前被选中的页
  unset ( $sub_pages ); //每次显示的页数
  unset ( $total_pages ); //总页数
  unset ( $page_tpl ); // 分页模板
  unset ( $pageparam ); //分页参数,默认page
  unset ( $pagelink );
  unset ( $static );
 }
 private function urlparameters($url = array()) {
  foreach ( $url as $key => $val ) {
   if ($key != $this->pageparam)
    $arg [] = $key . '=' . $val;
  }
  $arg [] = $this->pageparam . '=*';
  if ($this->static)
   return str_replace ( '{page}', '*', $this->pagelink );
  else
   return $this->pagelink . '?' . implode ( '&', $arg );
 }
 public function setpager($tpl_name = 'default', $tpl = '', $config = array()) {
  if (empty ( $tpl ))
   $tpl = $this->page_tpl ['default'] ['tpl'];
  if (empty ( $config ))
   $config = $this->page_tpl ['default'] ['config'];
  $this->page_tpl [$tpl_name] = array ('tpl' => $tpl, 'config' => $config );
 }
 public function getpager($tpl_name = 'default') {
  $this->getcurrentpage ();
  return $this->pager ( $this->page_tpl [$tpl_name] );
 }
 public function getcurrentpage() {
  $this->current_page = ($_get [$this->pageparam] <= intval ( $this->total_pages ) ? ($_get [$this->pageparam] < 1 ? 1 : $_get [$this->pageparam]) : intval ( $this->total_pages ));
 }
 public function pager($page_tpl = '') {
  if (empty ( $page_tpl ))
   $page_tpl = $this->page_tpl ['default'];
  $cfg = array ('recordcount' => intval ( $this->total_size ), 'pageindex' => intval ( $this->current_page ), 'pagecount' => intval ( $this->total_pages ), 'pagesize' => intval ( $this->page_size ), 'listlong' => intval ( $this->sub_pages ), 'listsidelong' => 2, 'list' => '*', 'currentclass' => 'current', 'link' => $this->urlparameters ( $_get ), 'first' => '&laquo;', 'prev' => '&#8249;', 'next' => '&#8250;', 'last' => '&raquo;', 'more' => '...', 'disabledclass' => 'disabled', 'jump' => 'input', 'jumpplus' => '', 'jumpaction' => '', 'jumplong' => 50 );
  if (! empty ( $page_tpl ['config'] )) {
   foreach ( $page_tpl ['config'] as $key => $val ) {
    if (array_key_exists ( $key, $cfg ))
     $cfg [$key] = $val;
   }
  }
  $tmps教程tr = $page_tpl ['tpl'];
  $pstart = $cfg ['pageindex'] - (($cfg ['listlong'] / 2) + ($cfg ['listlong'] % 2)) + 1;
  $pend = $cfg ['pageindex'] + $cfg ['listlong'] / 2;
  if ($pstart < 1) {
   $pstart = 1;
   $pend = $cfg ['listlong'];
  }
  if ($pend > $cfg ['pagecount']) {
   $pstart = $cfg ['pagecount'] - $cfg ['listlong'] + 1;
   $pend = $cfg ['pagecount'];
  }
  if ($pstart < 1)
   $pstart = 1;
  for($i = $pstart; $i <= $pend; $i ++) {
   if ($i == $cfg ['pageindex'])
    $plist .= '<span class="' . $cfg ['currentclass'] . '" >' . str_replace ( '*', $i, $cfg ['list'] ) . '</span> ';
   else
    $plist .= ' <a href="' . str_replace ( '*', $i, $cfg ['link'] ) . '"> ' . str_replace ( '*', $i, $cfg ['list'] ) . '</a> ';
  }
  if ($cfg ['listsidelong'] > 0) {
   if ($cfg ['listsidelong'] < $pstart) {
    for($i = 1; $i <= $cfg ['listsidelong']; $i ++) {
     $pliststart .= '<a href="' . str_replace ( '*', $i, $cfg ['link'] ) . '">' . str_replace ( '*', $i, $cfg ['list'] ) . '</a> ';
    }
    $pliststart .= ($cfg ['listsidelong'] + 1) == $pstart ? '' : $cfg ['more'] . ' ';
   } else {
    if ($cfg ['listsidelong'] >= $pstart && $pstart > 1) {
     for($i = 1; $i <= ($pstart - 1); $i ++) {
      $pliststart .= '<a href="' . str_replace ( '*', $i, $cfg ['link'] ) . '">' . str_replace ( '*', $i, $cfg ['list'] ) . '</a> ';
     }
    }
   }
   if (($cfg ['pagecount'] - $cfg ['listsidelong']) > $pend) {
    $plistend = ' ' . $cfg ['more'] . $plistend;
    for($i = (($cfg ['pagecount'] - $cfg ['listsidelong']) + 1); $i <= $cfg ['pagecount']; $i ++) {
     $plistend .= ' <a href="' . str_replace ( '*', $i, $cfg ['link'] ) . '"> ' . str_replace ( '*', $i, $cfg ['list'] ) . ' </a> ';
    }
   } else {
    if (($cfg ['pagecount'] - $cfg ['listsidelong']) <= $pend && $pend < $cfg ['pagecount']) {
     for($i = ($pend + 1); $i <= $cfg ['pagecount']; $i ++) {
      $plistend .= ' <a href="' . str_replace ( '*', $i, $cfg ['link'] ) . '"> ' . str_replace ( '*', $i, $cfg ['list'] ) . ' </a> ';
     }
    }
   }
  }
  if ($cfg ['pageindex'] > 1) {
   $pfirst = ' <a href="' . str_replace ( '*', '1', $cfg ['link'] ) . '">' . $cfg ['first'] . '</a> ';
   $pprev = ' <a href="' . str_replace ( '*', $cfg ['pageindex'] - 1, $cfg ['link'] ) . '">' . $cfg ['prev'] . '</a> ';
  } else {
   $pfirst = ' <span class="' . $cfg ['disabledclass'] . '">' . $cfg ['first'] . '</span> ';
   $pprev = ' <span class="' . $cfg ['disabledclass'] . '">' . $cfg ['prev'] . '</span> ';
  }
  if ($cfg ['pageindex'] < $cfg ['pagecount']) {
   $plast = ' <a href="' . str_replace ( '*', $cfg ['pagecount'], $cfg ['link'] ) . '">' . $cfg ['last'] . '</a> ';
   $pnext = ' <a href="' . str_replace ( '*', $cfg ['pageindex'] + 1, $cfg ['link'] ) . '">' . $cfg ['next'] . '</a> ';
  } else {
   $plast = ' <span class="' . $cfg ['disabledclass'] . '">' . $cfg ['last'] . '</span> ';
   $pnext = ' <span class="' . $cfg ['disabledclass'] . '">' . $cfg ['next'] . '</span> ';
  }
  switch (strtolower ( $cfg ['jump'] )) {
   case 'input' :
    $pjumpvalue = 'this.value';
    $pjump = '<input type="text" size="3" title="请输入要跳转到的页数并回车"' . (($cfg ['jumpplus'] == '') ? '' : ' ' . $cfg ['jumpplus']);
    $pjump .= ' onkeydown="网页特效:if(event.charcode==13||event.keycode==13){if(!isnan(' . $pjumpvalue . ')){';
    $pjump .= ($cfg ['jumpaction'] == '' ? ((strtolower ( substr ( $cfg ['link'], 0, 11 ) ) == 'javascript:') ? str_replace ( '*', $pjumpvalue, substr ( $cfg ['link'], 12 ) ) : " document.location.href='" . str_replace ( '*', ''+' . $pjumpvalue . '+'', $cfg ['link'] ) . '';') : str_replace ( "*", $pjumpvalue, $cfg ['jumpaction'] ));
    $pjump .= '}return false;}" />';
    break;
   case 'select' :
    $pjumpvalue = "this.options[this.selectedindex].value";
    $pjump = '<select ' . ($cfg ['jumpplus'] == '' ? ' ' . $cfg ['jumpplus'] . ' onchange="javascript:' : $cfg ['jumpplus']);
    $pjump .= ($cfg ['jumpaction'] == '' ? ((strtolower ( substr ( $cfg ['link'], 0, 11 ) ) == 'javascript:') ? str_replace ( '*', $pjumpvalue, substr ( $cfg ['link'], 12 ) ) : " document.location.href='" . str_replace ( '*', ''+' . $pjumpvalue . '+'', $cfg ['link'] ) . '';') : str_replace ( "*", $pjumpvalue, $cfg ['jumpaction'] ));
    $pjump .= '" title="请选择要跳转到的页数"> ';
    if ($cfg ['jumplong'] == 0) {
     for($i = 0; $i <= $cfg ['pagecount']; $i ++) {
      $pjump .= '<option value="' . $i . '"' . (($i == $cfg ['pageindex']) ? ' selected="selected"' : '') . ' >' . $i . '</option> ';
     }
    } else {
     $pjumplong = intval ( $cfg ['jumplong'] / 2 );
     $pjumpstart = ((($cfg ['pageindex'] - $pjumplong) < 1) ? 1 : ($cfg ['pageindex'] - $pjumplong));
     $pjumpstart = ((($cfg ['pagecount'] - $cfg ['pageindex']) < $pjumplong) ? ($pjumpstart - ($pjumplong - ($cfg ['pagecount'] - $cfg ['pageindex'])) + 1) : $pjumpstart);
     $pjumpstart = (($pjumpstart < 1) ? 1 : $pjumpstart);
     $j = 1;
     for($i = $pjumpstart; $i <= $cfg ['pageindex']; $i ++, $j ++) {
      $pjump .= '<option value="' . $i . '"' . (($i == $cfg ['pageindex']) ? ' selected="selected"' : '') . '>' . $i . '</option> ';
     }
     $pjumplong = $cfg ['pagecount'] - $cfg ['pageindex'] < $pjumplong ? $pjumplong : $pjumplong + ($pjumplong - $j) + 1;
     $pjumpend = $cfg ['pageindex'] + $pjumplong > $cfg ['pagecount'] ? $cfg ['pagecount'] : $cfg ['pageindex'] + $pjumplong;
     for($i = $cfg ['pageindex'] + 1; $i <= $pjumpend; $i ++) {
      $pjump .= '<option value="' . $i . '">' . $i . '</option> ';
     }
    }
    $pjump .= '</select>';
    break;
  }
  $patterns = array ('/{recordcount}/', '/{pagecount}/', '/{pageindex}/', '/{pagesize}/', '/{list}/', '/{liststart}/', '/{listend}/', '/{first}/', '/{prev}/', '/{next}/', '/{last}/', '/{jump}/' );
  $replace = array ($cfg ['recordcount'], $cfg ['pagecount'], $cfg ['pageindex'], $cfg ['pagesize'], $plist, $pliststart, $plistend, $pfirst, $pprev, $pnext, $plast, $pjump );
  $tmpstr = chr ( 13 ) . chr ( 10 ) . preg_replace ( $patterns, $replace, $tmpstr ) . chr ( 13 ) . chr ( 10 );
  unset ( $cfg );
  return $tmpstr;
 }
}
?>
[!--infotagslink--]

相关文章

  • C#中截取字符串的的基本方法详解

    这篇文章主要介绍了C#中截取字符串的的基本方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-11-03
  • php抓取网站图片并保存的实现方法

    php如何实现抓取网页图片,相较于手动的粘贴复制,使用小程序要方便快捷多了,喜欢编程的人总会喜欢制作一些简单有用的小软件,最近就参考了网上一个php抓取图片代码,封装了一个php远程抓取图片的类,测试了一下,效果还不错分享...2015-10-30
  • c#中判断字符串是不是数字或字母的方法

    这篇文章介绍了C#判断字符串是否数字或字母的实例,有需要的朋友可以参考一下...2020-06-25
  • PostgreSQL判断字符串是否包含目标字符串的多种方法

    这篇文章主要介绍了PostgreSQL判断字符串是否包含目标字符串的多种方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-02-23
  • 详解C++ string常用截取字符串方法

    这篇文章主要介绍了C++ string常用截取字符串方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-04-25
  • php字符串按照单词逐个进行反转的方法

    本文实例讲述了php字符串按照单词进行反转的方法。分享给大家供大家参考。具体分析如下:下面的php代码可以将字符串按照单词进行反转输出,实际上是现将字符串按照空格分隔到数组,然后对数组进行反转输出。...2015-03-15
  • mysql 批量更新与批量更新多条记录的不同值实现方法

    批量更新mysql更新语句很简单,更新一条数据的某个字段,一般这样写:复制代码 代码如下:UPDATE mytable SET myfield = 'value' WHERE other_field = 'other_value';如果更新同一字段为同一个值,mysql也很简单,修改下where即...2013-10-04
  • MySQL 字符串拆分操作(含分隔符的字符串截取)

    这篇文章主要介绍了MySQL 字符串拆分操作(含分隔符的字符串截取),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-22
  • C#实现字符串转换成字节数组的简单实现方法

    这篇文章主要介绍了C#实现字符串转换成字节数组的简单实现方法,仅一行代码即可搞定,非常简单实用,需要的朋友可以参考下...2020-06-25
  • 使用list stream: 任意对象List拼接字符串

    这篇文章主要介绍了使用list stream:任意对象List拼接字符串操作,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-09-09
  • C# 16 进制字符串转 int的方法

    这篇文章主要介绍了C# 16 进制字符串转 int的方法,非常不错,具有参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • 获取中文字符串的实际长度代码

    JS中默认中文字符长度和其它字符长度计算方法是一样的,但某些情况下我们需要获取中文字符串的实际长度,代码如下: 复制代码 代码如下: function strLength(str) { var realLength = 0, len = str.length, charCode = -1;...2014-06-07
  • EXCEL数据上传到SQL SERVER中的简单实现方法

    EXCEL数据上传到SQL SERVER中的方法需要注意到三点!注意点一:要把EXCEL数据上传到SQL SERVER中必须提前把EXCEL传到服务器上.做法: 在ASP.NET环境中,添加一个FileUpload上传控件后台代码的E.X: 复制代码 代码如下: if...2013-09-23
  • PostgreSQL 字符串处理与日期处理操作

    这篇文章主要介绍了PostgreSQL 字符串处理与日期处理操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-01
  • php二维码生成

    本文介绍两种使用 php 生成二维码的方法。 (1)利用google生成二维码的开放接口,代码如下: /** * google api 二维码生成【QRcode可以存储最多4296个字母数字类型的任意文本,具体可以查看二维码数据格式】 * @param strin...2015-10-21
  • Java生成随机姓名、性别和年龄的实现示例

    这篇文章主要介绍了Java生成随机姓名、性别和年龄的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-10-01
  • php 中英文混合字符串截取

    文章介绍一个实用的函数,我们如果用php substr来截取字符在中文上处理的很有问题,今天自己写了一个比较好的中文与英文字符截取的函数,有需要的朋友可以参考下。 ...2016-11-25
  • C#实现对字符串进行大小写切换的方法

    这篇文章主要介绍了C#实现对字符串进行大小写切换的方法,涉及C#操作字符串的技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • C#生成随机数功能示例

    这篇文章主要介绍了C#生成随机数功能,涉及C#数学运算与字符串操作相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • c#将字节数组转成易读的字符串的实现

    这篇文章主要介绍了c#将字节数组转成易读的字符串的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-06-25