Home >Backend Development >PHP Problem >How to convert 0010 to 10 in php

How to convert 0010 to 10 in php

青灯夜游
青灯夜游Original
2022-04-26 19:53:051396browse

Conversion method: 1. Use substr() to intercept the last two characters, the syntax is "substr($str,-2)". 2. Use substr_replace() to replace the two characters with null characters starting from the beginning of the string. The syntax is "substr_replace($str,"",0,2)".

How to convert 0010 to 10 in php

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

php will convert 0010 Method for 10:

1. Use substr()

substr() function to start from the third character of the string (index For 2) intercept 2 characters, or intercept all characters starting from the second to last character.

<?php
$str = "0010";
echo substr($str,2,2)."<br>";
echo substr($str,-2)."<br>";
?>

How to convert 0010 to 10 in php

2. Use the substr_replace() function

substr_replace() function starts from the beginning of the string and replaces the two Characters are replaced with empty characters

<?php
$str = "0010";
echo substr_replace($str,"",0,2);
?>

How to convert 0010 to 10 in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to convert 0010 to 10 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