$str='/闑鮹/login/..'
echo current(str_split($str,4))
echo current(str_split($str,4))
解决方案 »
- 请教:PHP变量如何到HTML,试过好多办法都不行,在线等,谢谢!!
- 提个很菜的问题,php session保护中的class/dbclass.inc文件是自己写的吗
- 请教POST以后,在HTTP协议中传输的数据是什么?
- 为何我的Web服务器非要定时重启才行?
- 高分求XML解析
- 急,简单的session问题
- 千分问题之一:详情请看内容(谁能答对送一千分,up者有分,up三次以上者没分,回答问题除外)
- 谁在用PHP4.3,为什么我从4.23换为4.3后连phpinfo()都不好使?
- unicode(utf-8)遇到中文的输入
- php判断是否4到11位数字
- 求PHP执行存储过程,返回多个记录集中.怎么再把值 print出来
- 怎样在数据库中返回多行数据?
前4个是 /字字/
要得到的是这两个字吧?用 / 分割字符串就得到了 嘿嘿 如果位置不固定 正则来的效率高也简单
没有简单的方法,如果装了mb_string,可以.
if (strlen($str_cut) > $length){
for($i=0; $i < $length; $i++)
if (ord($str_cut[$i]) > 128) $i++;
$str_cut = substr($str_cut,0,$i);
}
return $str_cut;
}$str_cut = '判o&r#d断一下就可以了';
$cc = substr_cut($str_cut,'4');
echo $cc;
<?php
preg_match("/(&#[0-9]+;|[a-z]+)(?1){3}/iU","闑鮹login",$match);
print_r($match); // ["闑鮹lo","闑"]
/**
* 你的意思没有表达得很清楚
* 直接说 源字符串是什么 要的结果是什么样子就行
* 还有一些特殊情况也要说明 比如那些字符串建有没其他字符 比如斜杠 数字什么的。
* 你说的含糊的 我都不知到你那里面的斜杠是字符串还是你用来说明截取点的。
*/?>
参考:
http://topic.csdn.net/u/20080331/14/012e0988-5a54-4831-b88b-7c34d4a4f522.htmlhttp://topic.csdn.net/u/20080411/17/a978257c-ae4b-4247-ad0b-78f424ff7597.html
{
for($i=0;$i<$len;$i++)
{
$temp_str=substr($str,0,1);
if(ord($temp_str) > 127)
//截取字符串第一字符的ascii码是否大于127,0-127的128个ASCII码代表了字母数字即一些标点符号等,超过此范围则为需要以unicode码显示
{
$i++;
if($i<$len)
{
$new_str[]=substr($str,0,3);
$str=substr($str,3);
}
}
else
{
$new_str[]=substr($str,0,1);
$str=substr($str,1);
}
}
return join($new_str);
}
<?php
preg_match_all("/(&#[0-9]+;|[a-z]+)/iU","/闑鮹/login/",$match);
$result = array_slice($match[1],0,4);
$result = implode('',$result);
echo $result;
// String "闑鮹lo"
?>
原码是html实体,可以先还原成html非实体,这样中文可以正常显示了第二步:中英文分离这个就多了,得看你的中英文是如何混排的,想要分成什么样的!可以字符串截取,也可以用正则用正则:英文就是26个字母构成的,中文则不是
{
/**
* powered by Smartpig
* mailto:[email protected]
*/
$length = 0;
if($len == "") $len = strlen($title);//判断起始为不正确位置
if($start > 0)
{
$cnum = 0;
for($i=0;$i<$start;$i++)
{
if(ord(substr($title,$i,1)) >= 128) $cnum ++;
}
if($cnum%2 != 0) $start--;
unset($cnum);
}if(strlen($title)<=$len) return substr($title,$start,$len);$alen = 0;
$blen = 0;$realnum = 0;for($i=$start;$i<strlen($title);$i++)
{
$ctype = 0;
$cstep = 0;
$cur = substr($title,$i,1);
if($cur == "&")
{
if(substr($title,$i,4) == "<")
{
$cstep = 4;
$length += 4;
$i += 3;
$realnum ++;
if($magic)
{
$alen ++;
}
}
else if(substr($title,$i,4) == ">")
{
$cstep = 4;
$length += 4;
$i += 3;
$realnum ++;
if($magic)
{
$alen ++;
}
}
else if(substr($title,$i,5) == "&")
{
$cstep = 5;
$length += 5;
$i += 4;
$realnum ++;
if($magic)
{
$alen ++;
}
}
else if(substr($title,$i,6) == """)
{
$cstep = 6;
$length += 6;
$i += 5;
$realnum ++;
if($magic)
{
$alen ++;
}
}
else if(substr($title,$i,6) == "'")
{
$cstep = 6;
$length += 6;
$i += 5;
$realnum ++;
if($magic)
{
$alen ++;
}
}
else if(preg_match("/&#(\d+);/i",substr($title,$i,8),$match))
{
$cstep = strlen($match[0]);
$length += strlen($match[0]);
$i += strlen($match[0])-1;
$realnum ++;
if($magic)
{
$blen ++;
$ctype = 1;
}
}
}else{
if(ord($cur)>=128)
{
$cstep = 2;
$length += 2;
$i += 1;
$realnum ++;
if($magic)
{
$blen ++;
$ctype = 1;
}
}else{
$cstep = 1;
$length +=1;
$realnum ++;
if($magic)
{
$alen++;
}
}
}
if($magic)
{
if(($blen*2+$alen) == ($len*2)) break;
if(($blen*2+$alen) == ($len*2+1))
{
if($ctype == 1)
{
$length -= $cstep;
break;
}else{
break;
}
}
}else{
if($realnum == $len) break;
}
}unset($cur);
unset($alen);
unset($blen);
unset($realnum);
unset($ctype);
unset($cstep);return substr($title,$start,$length);
}
<?phpprint m_substr("ss还是dd",1,3);
/*
现写的,大概是酱紫
*/
function m_substr($str)
{
preg_match_all("/[\x80-\xff]?./",$str,$arr);
if(func_num_args() == 2)
{
$len1 = func_get_arg(1);
return implode("",array_slice($arr[0],$len1));
}
if(func_num_args() >= 3)
{
$len1 = func_get_arg(1);
$len2 = func_get_arg(2);
return implode("",array_slice($arr[0],$len1,$len2));
}
}
?>