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; ?>
Use preg_replace:
preg_replace
preg_replace('~/.*~', '', $txt);
This removes everything starting the slash.
I would use preg_replace():
preg_replace()
$ip = '156.67.0.0/16'; $ip = preg_replace('#/\d+$#', '', $ip); echo $ip; // 156.67.0.0
trim() doesn't accept a regex but a caracter list. You can simply split the string and only use the first part though:
trim()
$parts = explode('/', $str); echo $parts[0];
rtrim accepts a character list, not a regular expression. Look into preg_replace.
rtrim
$end = preg_replace('@/.*$@', '', $txt);
Copyright © 2021 Jogjafile Inc.
Use
preg_replace
:This removes everything starting the slash.