- print_r: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$str = '123.23.23.4/17,';
$str .= '123.23.23.4/23,';
$str .= '123.23.23.4/8,';
$str .= '123.23.23.4/18';
preg_match_all("~/\K(?:[1-9]|[12][0-9]|3[01])\b~", $str, $matches);
print_r($matches[0]);