Heim > Artikel > Backend-Entwicklung > php trim用法求解,该如何处理
php trim用法求解
取一个ip的前三位字符串,大神帮我看下字符串'.'号为毛去不掉
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> $str='192.168.175.45'; $arr = explode('.',$str); array_pop($arr); $output = ''; foreach ($arr as $k){ $output .= '.'.$k; } ltrim($output,'.'); print_r($output);
$str='192.168.175.45'; $arr = explode('.',$str); array_pop($arr); $output = implode('.', $arr); print_r($output); <br><font color="#e78608">------解决方案--------------------</font><br>还可以这样写:<br>
$str='192.168.175.45'; echo substr($str, 0, strrpos($str, '.')); <br><font color="#e78608">------解决方案--------------------</font><br>你的源码
$str='192.168.175.45'; $arr = explode('.',$str); array_pop($arr); $output = ''; foreach ($arr as $k){ $output .= '.'.$k; } $output = ltrim($output,'.'); print_r($output); <div class="clear"> </div>