谁的错误:出乎意料的eregi()结果

blre 2001-07-13 10:42:28
/*------简单的程序-------*/
<?php
$s = 'ws $abc$ $koist$';
eregi('\$[^$]+\$',$s,$regs);
for($i=0;$i<10;$i++)
{
echo 'reg['.$i.'] = '.$regs[$i].' 长度:'.strlen($regs[$i]).'<br>';
}
?>

/*-------运行结果-------*/
reg[0] = $abc$ 长度:5
reg[1] = 长度:0
reg[2] = 长度:0
reg[3] = 长度:0
reg[4] = 长度:0
reg[5] = 长度:0
reg[6] = 长度:0
reg[7] = 长度:0
reg[8] = 长度:0
reg[9] = 长度:0

/*------函数说明 * 中文-------*/
ereg
字符串比对解析。
语法: int ereg(string pattern, string string, array [regs]);
返回值: 整数/数组
函数种类: 资料处理
内容说明
本函数以 pattern 的规则来解析比对字符串 string。
比对结果返回的值放在数组参数 regs 之中,regs[0]
内容就是原字符串 string、regs[1] 为第一个合乎规
则的字符串、regs[2] 就是第二个合乎规则的字符串,
余类推。若省略参数 regs,则只是单纯地比对,找到
则返回值为 true。
/*------函数说明 * 英文-------*/
eregi (PHP 3, PHP 4 )
eregi -- case insensitive regular expression match
Description
int eregi (string pattern, string string [, array regs])
This function is identical to ereg() except that this ignores case distinction when matching alphabetic characters.

ereg (PHP 3, PHP 4 )
ereg -- Regular expression match
Description
int ereg (string pattern, string string [, array regs])
Searches a string for matches to the regular expression given in pattern.
If matches are found for parenthesized substrings of pattern and the function is called with the third argument regs, the matches will be stored in the elements of the array regs. $regs[1] will contain the substring which starts at the first left parenthesis; $regs[2] will contain the substring starting at the second, and so on. $regs[0] will contain a copy of string.
If ereg() finds any matches at all, $regs will be filled with exactly ten elements, even though more or fewer than ten parenthesized substrings may actually have matched. This has no effect on ereg()'s ability to match more substrings. If no matches are found, $regs will not be altered by ereg().
Searching is case sensitive.
Returns true if a match for pattern was found in string, or false if no matches were found or an error occurred.
...全文
67 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
tinalover 2001-11-03
  • 打赏
  • 举报
回复
contact me.
blre 2001-07-13
  • 打赏
  • 举报
回复
运行配置
windows 2000 prof + sp2
apache 3.20
php 4.05

21,886

社区成员

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

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