Home > Backend Development > PHP Problem > How to remove the first dot in php

How to remove the first dot in php

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

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)".

How to remove the first dot in php

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

How to remove the first dot in php

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

How to remove the first dot in php

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!

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