php判断字符串的问题

sjw8072336 2010-10-28 05:18:42
比如说现在有个变量$c我想判断它是否在a-z之间,php有什么函数可以实现啊
‘sd$a’是否是'sda'-'sdz'之间的一个字符 怎么实现
不用循环的方式
...全文
92 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
在-云端 2010-10-28
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 lazysmile 的回复:]

引用 8 楼 heyc1998 的回复:
引用 4 楼 lazysmile 的回复:

[PHP]
if(preg_match("/^sd[a-z]$/",$str))
{
//匹配的情况
}
[PHP]

也请你看清楚lz的内容


这样的前提是你的前两位得是"sd"

请看清楚楼主的问题再说话
[/Quote]
LuciferStar 2010-10-28
  • 打赏
  • 举报
回复
长度用strlen来获取。
lazysmile 2010-10-28
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 heyc1998 的回复:]
引用 4 楼 lazysmile 的回复:

[PHP]
if(preg_match("/^sd[a-z]$/",$str))
{
//匹配的情况
}
[PHP]


这样的前提是你的前两位得是"sd"
[/Quote]
请看清楚楼主的问题再说话
在-云端 2010-10-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 lazysmile 的回复:]

[PHP]
if(preg_match("/^sd[a-z]$/",$str))
{
//匹配的情况
}
[PHP]
[/Quote]

这样的前提是你的前两位得是"sd"
ylongshao1987 2010-10-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 luciferstar 的回复:]

strcmp
(PHP 3, PHP 4 )

strcmp -- Binary safe string comparison
Description
int strcmp ( string str1, string str2)


Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, a……
[/Quote]
就这个可以了,楼主不是只要判断$c是否在a和z之间吗
lazysmile 2010-10-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 luciferstar 的回复:]
strcmp
(PHP 3, PHP 4 )

strcmp -- Binary safe string comparison
Description
int strcmp ( string str1, string str2)


Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, an……
[/Quote]
这样做的前提是$c是长度是3
在-云端 2010-10-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 luciferstar 的回复:]

strcmp
(PHP 3, PHP 4 )

strcmp -- Binary safe string comparison
Description
int strcmp ( string str1, string str2)


Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, a……
[/Quote]

顶!
lazysmile 2010-10-28
  • 打赏
  • 举报
回复
[PHP]
if(preg_match("/^sd[a-z]$/",$str))
{
//匹配的情况
}
[PHP]
LuciferStar 2010-10-28
  • 打赏
  • 举报
回复
strcmp
(PHP 3, PHP 4 )

strcmp -- Binary safe string comparison
Description
int strcmp ( string str1, string str2)


Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.

Note that this comparison is case sensitive.



跟sda比大,跟sdz比小即可。
sjw8072336 2010-10-28
  • 打赏
  • 举报
回复
怎么判断啊 我想找一个目录下面我想要的文件,因为文件名是‘sda’-‘sdz’之间
我不能因为一两个文件 就做全部循环啊 。有什么简单的方法没?
amani11 2010-10-28
  • 打赏
  • 举报
回复


if('sea' < 'sec' && 'sec' < 'sez')//只是例子,这是可以判断的,0-9a-z,可以是36进制的数

21,882

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧