php trim用法求解,该如何处理

WBOY
Release: 2016-06-13 10:14:28
Original
914 people have browsed it

php trim用法求解
取一个ip的前三位字符串,大神帮我看下字符串'.'号为毛去不掉

PHP code
<!--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);
Copy after login

输出 .192.168.175

------解决方案--------------------
$output=ltrim($output,'.');
print_r($output);
------解决方案--------------------
$output = ltrim($output,'.');

但这里根本就不需要用ltrim()处理:
PHP code
$str='192.168.175.45';$arr = explode('.',$str);array_pop($arr);$output = implode('.', $arr);print_r($output);<br><font color="#e78608">------解决方案--------------------</font><br>还可以这样写:<br>
Copy after login
PHP code
$str='192.168.175.45';echo substr($str, 0, strrpos($str, '.'));<br><font color="#e78608">------解决方案--------------------</font><br>你的源码
Copy after login
PHP code
$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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!