找到 ereg 函数的两个替代方案

发布于 2024-08-28 02:50:35 字数 316 浏览 3 评论 0原文

ereg 和 eregi 函数将从 Php 中删除。请帮助找到以下 ereg 函数的替代方案:

1) 仅允许特定范围的 IP 地址:

$targetAddr = "60.37..*..*";  
if (!ereg($targetAddr, $_SERVER['REMOTE_ADDR'])) {
die;
} 

2) 替换一系列点,例如............ ...

$message = ereg_replace("[.]{3,}", "... ", $message);

ereg and eregi functions will be deleted from Php. Please help to find alternatives for the following ereg functions:

1) To allow IP addresses only for specific ranges:

$targetAddr = "60.37..*..*";  
if (!ereg($targetAddr, $_SERVER['REMOTE_ADDR'])) {
die;
} 

2) To replace series of points like .......................

$message = ereg_replace("[.]{3,}", "... ", $message);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

王权女流氓 2024-09-04 02:50:35

只需使用 preg_match 和 < a href="http://www.php.net/manual/en/function.preg-replace.php" rel="nofollow noreferrer">preg_replace。这些正则表达式与 Perl 正则表达式语法的工作方式相同。

可能应该编写它

$targetAddr = "60[.]37[.].*[.].*";

但是,如果第一个正则表达式应该按照您所说的那样执行,则 。 (或者,使用反斜杠。)

Just use preg_match and preg_replace. Those regexes will work the same with Perl regex syntax.

However, the first regex should probably be written

$targetAddr = "60[.]37[.].*[.].*";

if it should do what you say it should. (Alternatively, use backslashes.)

挖鼻大婶 2024-09-04 02:50:35

这对我有用:

$targetAddr = "/^60\.37\..+/"; 
if (!preg_match($targetAddr, $_SERVER['REMOTE_ADDR'])) {
die;
}

$message = preg_replace("/[.]{3,}/", "... ", $message);

Thomas 和 Anomareh,你们的回答帮助我找到了正确的解决方案。谢谢。

This works for me:

$targetAddr = "/^60\.37\..+/"; 
if (!preg_match($targetAddr, $_SERVER['REMOTE_ADDR'])) {
die;
}

$message = preg_replace("/[.]{3,}/", "... ", $message);

Thomas and Anomareh, your answers helped me to find the right solution. Thank you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文