如何删除 IP 上的 CIDR 表示法?
我想摆脱 CIDR 表示法并尝试了以下方法,但它似乎不起作用:
<?php
$txt='156.67.0.0/16';
$re='(\\/)'.'(\\d+)';
$end = rtrim($txt,$re);
echo $end;
?>
I want to get rid of the CIDR notation and tried the following, but it doesn't seem to work like this:
<?php
$txt='156.67.0.0/16';
$re='(\\/)'.'(\\d+)';
$end = rtrim($txt,$re);
echo $end;
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
trim()
不接受正则表达式,但接受字符列表。您可以简单地拆分字符串并仅使用第一部分:trim()
doesn't accept a regex but a caracter list. You can simply split the string and only use the first part though:使用
preg_replace
:这会删除从削减。
Use
preg_replace
:This removes everything starting the slash.
rtrim
接受字符列表,而不是正则表达式。查看preg_replace
。rtrim
accepts a character list, not a regular expression. Look intopreg_replace
.我会使用
preg_replace()
:I would use
preg_replace()
: