Home >Backend Development >PHP Problem >How to replace Chinese colon in php
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)”.
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 = 'hello:world:hello:world'; echo "原字符串: ".$str."<br>"; $replace = '-'; $search = ':'; echo str_replace($search, $replace, $str)."<br>"; echo str_ireplace($search, $replace, $str); ?>
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!