如何看检验一个字符串是否在一串字符串里

loswing 2003-10-16 12:14:15
我在写一个文件管理系统:
我想让文件管理者可以对每个文件进行分级授权外;还可以对个别用户授权。
我用text来存储被授权用户;
(name1|name2|...)
可是如何检查一个name是否存在?
有没有去他更好的方法进行个别用户授权?
...全文
56 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
blueoxygen 2003-10-16
  • 打赏
  • 举报
回复
strpos
(PHP 3, PHP 4 )

strpos -- Find position of first occurrence of a string
Description
int strpos ( string haystack, string needle [, int offset])


Returns the numeric position of the first occurrence of needle in the haystack string. Unlike the strrpos(), this function can take a full string as the needle parameter and the entire string will be used.

If needle is not found, returns FALSE.

注: It is easy to mistake the return values for "character found at position 0" and "character not found". Here's how to detect the difference:


// in PHP 4.0b3 and newer:
$pos = strpos($mystring, "b");
if ($pos === false) { // note: three equal signs
// not found...
}

// in versions older than 4.0b3:
$pos = strpos($mystring, "b");
if (!is_integer($pos)) {
// not found...
}





If needle is not a string, it is converted to an integer and applied as the ordinal value of a character.

The optional offset parameter allows you to specify which character in haystack to start searching. The position returned is still relative to the the beginning of haystack.

ustb 2003-10-16
  • 打赏
  • 举报
回复
数据库没有设计好,被授权用户不是原子组
zhangking 2003-10-16
  • 打赏
  • 举报
回复
asp: inStr(str,yourstr)>0,在;<0 不在
feel8 2003-10-16
  • 打赏
  • 举报
回复
读出text内的内容,用explode把每个人的名字读入数组。校验。
loswing 2003-10-16
  • 打赏
  • 举报
回复
strpos()用不了。
我用两个函数 ;
//将字符串分开为 array
function cut_char($str)
{
$ar=explode("|",$str);
return $ar;
}

//数组偏离检查匹配
function check_ar($a,$str)
{
foreach($str as $key=>$value)
{
if($a==$value)
{
$str=0;
break;
}
else
{
$str=1;
}
}
return $str;
}

21,886

社区成员

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

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