另一个 php ereg 修复
我需要从 ereg 到 preg_match 进行一小段编码。这是代码。
function be_file_list($d, $x) {
foreach (array_diff(scandir($d), array('.', '..')) as $f) {
if (is_file($d . '/' . $f) && (($x) ? ereg($x.'$',$f) : 1)) {
$l[] = $f;
}
}
return $l;
}
这段代码可以按预期工作,即使它看起来不太漂亮 (来源:http://www.php.net/manual/en/function .scandir.php),
但由于 ereg 已被弃用,我真的很想让它成为 preg_match 或类似的东西。
我整个下午都在搞乱这个,电脑快要被淘汰了。我本以为这
preg_match("/"$x.'$',$f"/")
会起作用,但没有骰子。
任何帮助都会很棒。
干杯 本
I have a small chunk of coding I need to take from ereg to preg_match. Here is the code.
function be_file_list($d, $x) {
foreach (array_diff(scandir($d), array('.', '..')) as $f) {
if (is_file($d . '/' . $f) && (($x) ? ereg($x.'
This code works as expected even if it doesn't look too pretty
(source: http://www.php.net/manual/en/function.scandir.php)
but as ereg is deprecated, I would really like to make it preg_match, or something like that.
I have been messing with this all afternoon and the PC is about to go out the window. I would have thought that
preg_match("/"$x.'
would have worked but no dice.
Any help would be great.
Cheers
Ben
,$f) : 1)) {
$l[] = $f;
}
}
return $l;
}
This code works as expected even if it doesn't look too pretty
(source: http://www.php.net/manual/en/function.scandir.php)
but as ereg is deprecated, I would really like to make it preg_match, or something like that.
I have been messing with this all afternoon and the PC is about to go out the window. I would have thought that
would have worked but no dice.
Any help would be great.
Cheers
Ben
,$f"/")
would have worked but no dice.
Any help would be great.
Cheers
Ben
This code works as expected even if it doesn't look too pretty
(source: http://www.php.net/manual/en/function.scandir.php)
but as ereg is deprecated, I would really like to make it preg_match, or something like that.
I have been messing with this all afternoon and the PC is about to go out the window. I would have thought that
would have worked but no dice.
Any help would be great.
Cheers
Ben
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你完全错了......尝试
你写道:
你需要在字符串和变量之间使用
.
,并且你的尾部斜杠位于错误的位置。它需要在模式之后,而不是在主题之后。You've got it all wrong... try
You wrote:
You need
.
s between the strings and vars, and you've got your trailing slash in the wrong place. It needs to be after the pattern, not after the subject.看起来 glob 就是您要找的东西。结合目录读取和正则表达式
Looks like glob is the thing you're looking for. Combining both directory reading and regular expressions