Home  >  Article  >  Backend Development  >  How to remove 0 from string in php

How to remove 0 from string in php

青灯夜游
青灯夜游Original
2022-04-27 14:43:302786browse

Method: 1. Use "trim($str,"0")" to remove the 0's at both ends of the string; 2. Use "str_replace("0","",$str)" to remove Remove all 0s from the string; 3. Use "substr_replace($str,"",position value,1)" to remove 0s at the specified position.

How to remove 0 from string in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php removes strings 0

1. Use the trim() function

Use the trim() function to remove the 0

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$str = "0dfd0125e0reg0";
echo "原字符串:".$str;
echo "<br>处理后:".trim($str,"0");
?>
# at both ends of the string.

How to remove 0 from string in php

##2. Use the str_replace() function

Use the str_replace() function to remove all 0

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$str = "0dfd0125e0reg0";
echo "原字符串:".$str;
echo "<br>处理后:".str_replace("0","",$str);
?>

from the string

How to remove 0 from string in php

3. Use the substr_replace() function

Use the substr_replace() function to remove 0

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$str = "0dfd0125e0reg0";
echo "原字符串:".$str."<br><br>";
echo "去除开头的0:".substr_replace($str,"",0,1)."<br><br>";
echo "去除末尾的0:".substr_replace($str,"",-1,1)."<br><br>";
echo "去除第5字符0:".substr_replace($str,"",4,1)."<br><br>";
echo "去除第10字符0:".substr_replace($str,"",9,1)."<br><br>";
?>

## at the specified position in the string

How to remove 0 from string in php# Recommended learning: "

PHP Video Tutorial

"

The above is the detailed content of How to remove 0 from string 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