很多站长朋友们都不太清楚英文+数字php,今天小编就来给大家整理英文+数字php,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 PHP指定截取字符串中的中英文或数字字符的实例分享 2、 php批量获取首字母(汉字、数字、英文) 3、 php 判断 用户名 英文或者数字 4、 php 英文数字编号 如何数字自增 5、 PHP 随机生成英文数字交替 6、 php英文与数字比较按什么进行 PHP指定截取字符串中的中英文或数字字符的实例分享我们在开发过程中,经常会碰到截取中文英文数字等的问题,大家知道中文所占的字符和英文数字是不同的;然后我们就会在项目的common里写一些日常的函数包含时间计算转换和中英文字符截取的函数;比如截取中英文的函数没个几行代码恐怕拿不下来的吧,现在就告诉大家一个简单的(自己本地运行过的),如有问题,请大家多多指教
$c
=
'ddaabbccaa';
$d
=
'地球需要我们每个人的爱护';
$frist1
=
mb_substr(
$c,
0,
1
,"UTF-8");
//
d
$delete_last1
=
mb_substr($d,
-1,1,"UTF-8");
//
护
echo
$frist1.'+++'.$delete_last1.'<br/>';
//
d+++护
$frist2
=
mb_substr(
$d,
0,
1
,"UTF-8");
//
地
$delete_last2
=
mb_substr($d,
-1,1,"UTF-8");
//
护
echo
$frist2.'+++'.$delete_last2.'<br/>';
//
地+++护
$e
=
'11aa22cc33';
$f
=
'aa地球需要我们每个人的爱护';
$g
=
'地球需要我们每个人的爱护gg';
$h
=
'地球需要我们每个人的爱护';
$first3
=
mb_substr(
$e,
0,
1
,"UTF-8");
//
1
$last3
=
mb_substr(
$f,
0,
1
,"UTF-8");
//
a
$delete_last3
=
mb_substr($f,
-1,1,"UTF-8");
//
护
$delete_last4
=
mb_substr($g,
-1,1,"UTF-8");
//
g
$frist4
=
mb_substr(
$g,
0,
1
,"UTF-8");
//
地
$delete_last5
=
mb_substr($h,
-1,1,"UTF-8");
//
护
echo
$first3.'+++'.$last3.'---'.$delete_last3.'***'.$delete_last4.''.$frist4.'<br/>';
//
1+++a---护***g地
echo
$last3.'...'.$delete_last3.'<br/>';
//
a...护
echo
$frist4.'...'.$delete_last5.'<br/>';
//
地...护
//
这样不管字符串里是中英文数字等都是可以的无需判断,如:
”地...护“
或者
“地...”
或者
“...护”
PS:过滤字符串中空格的方法
去除字符串首尾中英文空格的方法:
function
mbTrim($str)
{
return
mb_ereg_replace('(^(|
)+|(|
)+$)',
'',
$str);
}
下面的正则验证时过滤掉用户输入的连续空格,包括全角空格和半角空格
$user
=
mb_ereg_replace('^(|
)+',
'',
$user);
$user
=
mb_ereg_replace('(|
)+$',
'',
$user);
$age
=
mb_ereg_replace('^(|
)+',
'',
$age);
$age
=
mb_ereg_replace('(|
)+$',
'',
$age);
$method
=
mb_ereg_replace('^(|
)+',
'',
$method);
$method
=
mb_ereg_replace('(|
)+$',
'',
$method);
$address
=
mb_ereg_replace('^(|
)+',
'',
$address);
$address
=
mb_ereg_replace('(|
)+$',
'',
$address);
php批量获取首字母(汉字、数字、英文)php批量获取首字母(汉字 数字 英文)
$mysql_server_name= ; //改成自己的mysql数据库服务器
$mysql_username= 用户 ; //改成自己的mysql数据库用户名
$mysql_password= 密码 ; //改成自己的mysql数据库密码
$mysql_database= 数据库 ; //改成自己的mysql数据库名
mysql_connect( $mysql_username $mysql_password) or die( database not access );
mysql_select_db($mysql_database);
mysql_query("SET NAMES utf ");
$equery = " select title from 表 ";
$result =mysql_query($equery );
while ($row = mysql_fetch_array($result MYSQL_BOTH))
{
$title=$row["title"];
if (ord($title)> ) { //汉字开头
echo $letter=getfirstchar($title);
}else if(ord($title)>= and ord($title)<= ){ //数字开头
echo $letter=iconv_substr($title utf );
}else if(ord($title)>= and ord($title)<= ){ //大写英文开头
echo $letter=iconv_substr($title utf );
}else if(ord($title)>= and ord($title)<= ){ //小写英文开头
echo $letter=iconv_substr($title utf );
}
}
function getfirstchar($s ){
$s=iconv("UTF " "gb " $s );
$asc=ord($s{ })* +ord($s{ }) ;
if($asc>= and $asc<= )return "A";
if($asc>= and $asc<= )return "B"; if($asc>= and $asc<= )return "C";
if($asc>= and $asc<= )return "D";
if($asc>= and $asc<= )return "E";
if($asc>= and $asc<= )return "F";
if($asc>= and $asc<= )return "G";
if($asc>= and $asc<= )return "H";
if($asc>= and $asc<= )return "J";
if($asc>= and $asc<= )return "K";
if($asc>= and $asc<= )return "L";
if($asc>= and $asc<= )return "M";
if($asc>= and $asc<= )return "N";
if($asc>= and $asc<= )return "O";
if($asc>= and $asc<= )return "P";
if($asc>= and $asc<= )return "Q";
if($asc>= and $asc<= )return "R";
if($asc>= and $asc<= )return "S";
if($asc>= and $asc<= )return "T";
if($asc>= and $asc<= )return "W";
if($asc>= and $asc<= )return "X";
if($asc>= and $asc<= )return "Y";
if($asc>= and $asc<= )return "Z";
return false;
lishixinzhi/Article/program/PHP/201311/20913
php 判断 用户名 英文或者数字用正则来判断,如检查是否数字的代码: 1 2 if(preg_match("/^\d*$/",$fgid)) echo('是数字'); else echo('不是数字'); 验证由26个英文字母组成的字符串:^[A-Za-z]+$ 验证由26个大写英文字母组成的字符串:^[A-Z]+$ 验证由数字和26个英文字母组成的字符串:^[A-Za-z0-9]+$
php 英文数字编号 如何数字自增朋友可能你要的是 PHPExcel的自增吧?
可以选择在循环外赋初值,然后在循环内进行自增,并且可循环标题与数据
标题为:
$i = 'A';
foreach ($col_name as $val) {
$col_title = $i . '1'; //每次给这个值进行更改 即 第一次A1,第二次B1,第三次C1
//执行相应操作
$i++;
}
上面是标题头的循环,内容部分的循环一样类似的语句就可以了
PHP 随机生成英文数字交替很简单:
<?
$a=array('a','b','c',......);//我省略了哦
$b=array('0','1','2',......);
$c='';
for($i=0;$i<8;$i++){
if(fmod($i,2)==0){
$c.=$a[rand(0,25)];
}else{
$c.=$b[rand(0,9)];
}
}
echo($c);
?>
php英文与数字比较按什么进行要按字节顺序进行字符串的比较。
可以使用strcmp()和strcasecmp()两个函数,其中函数strcasecmp()可以忽略字符串中字母的大小写进行比较。这两个函数的原型如下所示。
2instrcmp(stringstr1,stringstr2)//区分字符串中字母大小写地比较。
intstrcasecmp(stringstr1,stringstr2)//忽略字符串中字母大小写地比较。
关于英文+数字php的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于英文+数字php 英文+数字条件筛选怎么操作的详细内容...