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

How to convert 0010 to 10 in php

青灯夜游
Release: 2023-03-15 20:44:01
Original
1382 people have browsed it

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

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

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!

Related labels:
php
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