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.
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('content-type:text/html;charset=utf-8'); $str = "123.567"; echo "原字符串:".$str."<br>"; $new = str_replace(".","",$str); echo "新字符串:".$new; ?>
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('content-type:text/html;charset=utf-8'); $str = "3.1415"; echo "原字符串:".$str."<br>"; $new = substr_replace($str,"",stripos($str,"."),1); echo "新字符串:".$new; ?>
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!