Home >Backend Development >PHP Problem >How to remove the first dot in php
Removal method: 1. Use stripos() to get the position of the first point, the syntax is "stripos($str,".")"; 2. Use substr_replace() to replace it based on the obtained position. Replace with null character, syntax "substr_replace($str,"",position,1)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
If a string contains multiple dot characters ".", then how to remove the first point? Here's how to use php to remove the first dot of a string.
php method to remove the first dot
1. Use stripos() to get the occurrence position of the first dot character "."
<?php $str = "1.2.3.4.5.6.7"; echo stripos($str,"."); ?>
Because string counting starts from 0, 1 is returned.
2. Use the substr_replace() function to replace the character with an empty character according to the obtained position
<?php $str = "1.2.3.4.5.6.7"; echo substr_replace($str,"",stripos($str,"."),1); ?>
Recommended learning: "PHP Video Tutorial》
The above is the detailed content of How to remove the first dot in php. For more information, please follow other related articles on the PHP Chinese website!