Home Backend Development PHP Tutorial php trim用法求解,该如何处理

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

Jun 13, 2016 pm 01:40 PM
arr ltrim output str

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
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Front-end output settings Front-end output settings Feb 19, 2024 am 09:30 AM

Front-end output configuration requires specific code examples. In front-end development, output configuration is a very important configuration. It is used to define the file path, file name and related resource paths generated after the project is packaged. This article will introduce the role of front-end output configuration, common configuration options, and give specific code examples. The role of output configuration: The output configuration item is used to specify the file path and file name generated after the project is packaged. It determines the final output of the project. Packaged in webpack etc.

Python built-in type str source code analysis Python built-in type str source code analysis May 09, 2023 pm 02:16 PM

1The basic unit of Unicode computer storage is the byte, which is composed of 8 bits. Since English only consists of 26 letters plus a number of symbols, English characters can be stored directly in bytes. But other languages ​​(such as Chinese, Japanese, Korean, etc.) have to use multiple bytes for encoding due to the large number of characters. With the spread of computer technology, non-Latin character encoding technology continues to develop, but there are still two major limitations: no multi-language support: the encoding scheme of one language cannot be used in another language and there is no unified standard: for example There are many encoding standards in Chinese such as GBK, GB2312, GB18030, etc. Since the encoding methods are not unified, developers need to convert back and forth between different encodings, and many errors will inevitably occur.

Output, the core concept of webpack Output, the core concept of webpack Aug 09, 2022 pm 06:32 PM

Once you have all your assets together, you need to tell webpack where to package your application. The output attribute of webpack describes how to handle bundled code. The following article will give you an in-depth understanding of the output (Output) in the core concept of webpack. I hope it will be helpful to you!

What are the similarities and differences between __str__ and __repr__ in Python? What are the similarities and differences between __str__ and __repr__ in Python? Apr 29, 2023 pm 07:58 PM

What are the similarities and differences between __str__ and __repr__? We all know the representation of strings. Python's built-in function repr() can express objects in the form of strings to facilitate our identification. This is the "string representation". repr() obtains the string representation of an object through the special method __repr__. If __repr__ is not implemented, when we print an instance of a vector to the console, the resulting string may be. >>>classExample:pass>>>print(str(Example()))>>>

Use PHP function 'ltrim' to remove whitespace characters on the left side of a string Use PHP function 'ltrim' to remove whitespace characters on the left side of a string Jul 24, 2023 am 09:45 AM

Title: Use the PHP function "ltrim" to remove whitespace characters on the left side of a string. In PHP programming, you often encounter situations where you need to process strings. The left side of the string may contain blank characters, and these blank characters may affect our further processing of the string. In order to solve this problem, PHP provides the "ltrim" function, which can easily remove the whitespace characters on the left side of the string. This article will introduce the use of the "ltrim" function and provide some code examples to show its practical application

PHP output GD image to browser or file PHP output GD image to browser or file Mar 21, 2024 am 10:41 AM

This article will explain in detail how PHP outputs GD images to a browser or file. I think it is quite practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP outputs GD images to a browser or file Introduction The phpGD library provides powerful functions for processing images, allowing you to create, edit and output images. Images can be output to a browser or file for display or further processing. Output to Browser To output an image to a browser, use the following steps: Create an image resource: Use the imagecreate() function to create an image resource. Load image data: use imagepng(), imagejpeg() or imagegif()

Steps for exporting wps2019 tables to pictures Steps for exporting wps2019 tables to pictures Mar 27, 2024 pm 04:51 PM

1. Use wps2019 to open the table to be edited. 2. Click the [File] menu item in the upper left corner of the wps2019 window. 3. In the pop-up file drop-down menu, click the menu item [Export as Image]. 4. A window for outputting to pictures will pop up. Select the output quality format in the window. 5. Click the Format drop-down menu and select the format you want to save as an image in the pop-up menu. 6. Finally, click the Save to back option button to set the location where you want to save the image. 7. After clicking OK, a prompt indicating successful output will pop up after a while.

Revealing the secret of str in Go language Revealing the secret of str in Go language Mar 29, 2024 am 11:27 AM

Go language is a fast, concise and efficient open source programming language, which is becoming more and more popular among programmers. String (string) is one of the data types frequently used in programs, and it also has a unique processing method in the Go language. This article will lead readers to uncover the mystery of strings (str) in Go language, and analyze its usage and characteristics through specific code examples. Definition and initialization of string In Go language, a string is a sequence of characters wrapped in double quotes "", for example: str

See all articles