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

青灯夜游
Release: 2023-03-16 16:52:02
Original
2869 people have browsed it

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 is "str_replace("//","" , string)". 2. Use the preg_replace() function and regular expression to match the "//" substring and replace it with a null character. The syntax is "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 str_replaceh() The function removes the "//" characters from the string

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

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

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 them with the empty characters ''.

Regular expression used: /\//

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$str= &#39;//123//34kh9//8jjhg//&#39;;
echo "原字符串:".$str."<br>";
$regex = "/\//";
$newStr=preg_replace($regex,"", $str);
echo "新字符串:".$newStr;
?>
Copy after login

How to remove // character from string in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to remove '//' character from string 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