Home  >  Article  >  Backend Development  >  How to replace Chinese colon in php

How to replace Chinese colon in php

青灯夜游
青灯夜游Original
2022-02-21 19:16:581791browse

php method to replace Chinese colon: 1. Use str_ireplace() function, syntax "str_ireplace(Chinese colon, replacement value, $str)"; 2. Use str_replace() function, syntax "str_replace(Chinese colon ,replacement value,$str)”.

How to replace Chinese colon in php

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

In php, you can use str_ireplace() and str_replace() function to replace Chinese colons in strings.

str_ireplace() and str_replace use a new string to replace a specific string specified in the original string. str_replace is case-sensitive, while str_ireplace() is not case-sensitive. The syntax of the two is similar.

The syntax of str_ireplace() is as follows:

mixed str_ireplace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )

These two functions return a string or array. This string or array is the result of replacing all search in subject with replace. The parameter count represents the number of times to perform the replacement.

Usage examples are as follows:

<?php  
header("content-type:text/html;charset=utf-8");
$str = &#39;hello:world:hello:world&#39;;
echo "原字符串: ".$str."<br>";
$replace = &#39;-&#39;;
$search = &#39;:&#39;;
echo str_replace($search, $replace, $str)."<br>";
echo str_ireplace($search, $replace, $str);
?>

How to replace Chinese colon in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to replace Chinese colon in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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