Home >Backend Development >PHP Problem >How to remove characters from string in php

How to remove characters from string in php

王林
王林Original
2020-11-05 15:17:072228browse

php method to remove characters from a string: You can use the built-in function str_replace to achieve this, such as [str_replace($find,$replace,$arr)]. This function can replace some characters in a string and return a string or array with the replacement values.

How to remove characters from string in php

str_replace() function replaces some characters in a string (case sensitive) and returns a string or array with the replacement value.

(Recommended tutorial: java video tutorial)

Syntax:

str_replace(find,replace,string,count)

Parameter introduction:

find Required. Specifies the value to look for.​

replace Required. Specifies the value to replace the value in find .​

string Required. Specifies the string to be searched for.

count Optional. A variable counting the number of substitutions.

Example:

<?php
$find = array("Hello","world");
$replace = array("B");
$arr = array("Hello","world","!");
print_r(str_replace($find,$replace,$arr));
?>

Related recommendations:php training

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