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)".
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>"; ?>
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); ?>
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!