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

How to remove 0 from string in php

青灯夜游
Release: 2023-03-15 21:06:01
Original
2861 people have browsed it

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");
?>
Copy after login
# 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);
?>
Copy after login

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>";
?>
Copy after login
## 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!

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