Home > Backend Development > PHP Problem > How to remove decimal point from php string

How to remove decimal point from php string

青灯夜游
Release: 2023-03-15 19:08:02
Original
3078 people have browsed it

Method: 1. Use the "str_replace(".","",$str)" statement to find the decimal point and replace it with a null character; 2. Use "substr_replace($str,"", stripos($str,"."),1)" statement, replace the decimal point with a null character according to its position.

How to remove decimal point from php string

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

Remove the php string Decimal point method

Method 1: Use str_replace() function

You can use the str_replace() function to find the decimal point "." and replace it Just change it to the empty characters "".

Example:

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$str = "123.567";
echo "原字符串:".$str."<br>";
$new = str_replace(".","",$str);
echo "新字符串:".$new;
?>
Copy after login

How to remove decimal point from php string

Method 2: Use stripos() substr_replace() function

  • Use stripos() to get the position of the decimal point "."

  • Use substr_replace() to replace the decimal point "." with the empty character "" according to the obtained position.

Example:

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$str = "3.1415";
echo "原字符串:".$str."<br>";
$new = substr_replace($str,"",stripos($str,"."),1);
echo "新字符串:".$new;
?>
Copy after login

How to remove decimal point from php string

Recommended learning: "PHP Video Tutorial"

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