Home  >  Article  >  Backend Development  >  How to remove the 0 on the left in php

How to remove the 0 on the left in php

藏色散人
藏色散人Original
2021-12-08 09:16:042681browse

php method to remove the 0 on the left: 1. Create a new php file; 2. Create a numeric variable starting with 0; 3. Use the preg_replace function and use the regular expression "/^0 /", Just replace one or more 0s in front of the variable with nothing.

How to remove the 0 on the left in php

#The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.

php How to remove the 0 on the left?

Create a new php file, named test.php, to explain how to remove the 0 in front of the number in php.

How to remove the 0 on the left in php

In the test.php file, use the header() method to set the encoding format of the page to utf-8 to avoid outputting Chinese garbled characters.

How to remove the 0 on the left in php

In the test.php file, create a numeric variable starting with 0 for testing.

How to remove the 0 on the left in php

In the test.php file, use the preg_replace function and use the regular expression "/^0 /" to replace one or more 0s in front of the variable with nothing.

How to remove the 0 on the left in php

In the test.php file, use echo to output the processed numbers.

How to remove the 0 on the left in php

Open the test.php file in the browser to view the results.

How to remove the 0 on the left in php

Recommended study: "PHP Video Tutorial"

The above is the detailed content of How to remove the 0 on the left in php. For more information, please follow other related articles on the PHP Chinese website!

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