• notice
  • Congratulations on the launch of the Sought Tech site

How to remove the "//" character from a string in php

This article mainly introduces "How php removes the "//" character in a string". In daily operations, I believe many people have doubts about how php removes the "//" character in a string. The editor checked it out. All kinds of information, sorting out simple and easy-to-use operation methods, I hope it will help you to answer your doubts about "how to remove the "//" character in a string in php"! Next, please follow the editor to learn together!

Two removal methods: 1. Use the str_replaceh() function to search for the "//" substring in the string and replace it with an empty character, the syntax "str_replace("//","",string)". 2. Use the preg_replace() function and regular expressions to match the "//" substring and replace it with an empty character, the syntax "preg_replace("/\//","", string)".

How to remove "//" character from string in php

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

Method 1: Use the str_replaceh() function to remove the "//" characters in the string

Use str_replaceh() to search for the "//" substring and replace it with an empty character.

<?php 
header( 'content-type:text/html;charset=utf-8' );   
$str=  '123//34kh9//8jjhg//' ;
 echo  "Original string: " .$str. "<br>" ;
$newStr=str_replace( "//" , "" ,$str);
 echo  "New string: " .$newStr;
 ?>

How to remove "//" character from string in php

Method 2: Use the preg_replace() function and regular expressions to remove the "//" characters in the string

Use regular expressions to search for all " //" in the string and replace it with empty characters ''.

Regular expression used:/\//

<?php 
header( 'content-type:text/html;charset=utf-8' );   
$str=  '//123//34kh9//8jjhg//' ;
 echo  "Original string: " .$str. "<br>" ;
$regex =  "/\//" ;
$newStr=preg_replace($regex, "" , $str);
 echo  "New string: " .$newStr;
 ?>

How to remove "//" character from string in php

At this point, the study of "how to remove "//" characters in strings in php" is over, and I hope to solve your doubts. The combination of theory and practice can better help everyone learn, go try it!


Tags

Technical otaku

Sought technology together

Related Topic

0 Comments

Leave a Reply

+