str_ireplace
Description
The str_ireplace of String for PHP case-insensitive version of str_replace().
Syntax
str_ireplace( array|string $search, array|string $replace, string|array $subject, int &$count = null ): string|array
Parameters
search
The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles.
replace
The replacement value that replaces found search values. An array may be used to designate multiple replacements.
subject
The string or array being searched and replaced on, otherwise known as the haystack. If subject is an array, then the search and replace is performed with every entry of subject, and the return value is an array as well.
count
If passed, this will be set to the number of replacements performed.
Return
Returns a string or an array of replacements.
Examples
1 · search replace subject
<? $search = "case"; $replace = "replace"; $subject = "case Case CASE"; $return = str_ireplace($search, $replace, $subject); echo $return;
replace replace replace
2 · count
<? $search = "case"; $replace = "replace"; $subject = "case Case CASE"; $return = str_ireplace($search, $replace, $subject, $count); echo $count;
3
3
<? $search = array("search1", "search2", "search3"); $replace = "replace"; $subject = "search1 search2 search3"; $return = str_ireplace($search, $replace, $subject); echo $return;
replace replace replace
4
<? $search = array("search1", "search2", "search3"); $replace = array("replace1", "replace2", "replace3"); $subject = "search1 search2 search3"; $return = str_ireplace($search, $replace, $subject); echo $return;
replace1 replace2 replace3
5
<? $search = array("\r\n", "\n", "\r"); // \r\n first $replace = "<br>"; $subject = "line\nline\rline\r\nline"; $return = str_ireplace($search, $replace, $subject); echo $return;
line<br>line<br>line<br>line
6
<? $search = array('a', 'b', 'c', 'd', 'e'); $replace = array('b', 'c', 'd', 'e', 'f'); $subject = 'a'; $return = str_ireplace($search, $replace, $subject); echo $return;
f
7
<? $search = array('a', 'p'); $replace = array('apple', 'pear'); $subject = 'a p'; $return = str_ireplace($search, $replace, $subject); echo $return;
apearpearle pear
Links
Related
String
- addcslashes
- addslashes
- bin2hex
- chop
- chr
- chunk_split
- convert_uudecode
- convert_uuencode
- count_chars
- crc32
- crypt
- echo
- explode
- fprintf
- get_html_translation_table
- hebrev
- hebrevc
- hex2bin
- html_entity_decode
- htmlentities
- htmlspecialchars
- htmlspecialchars_decode
- implode
- join
- lcfirst
- levenshtein
- localeconv
- ltrim
- md5
- md5_file
- metaphone
- nl_langinfo
- nl2br
- number_format
- ord
- parse_str
- printf
- quoted_printable_decode
- quoted_printable_encode
- quotemeta
- rtrim
- setlocale
- sha1
- sha1_file
- similar_text
- soundex
- sprintf
- sscanf
- str_contains
- str_decrement
- str_ends_with
- str_getcsv
- str_increment
- str_pad
- str_repeat
- str_replace
- str_rot13
- str_shuffle
- str_split
- str_starts_with
- str_word_count
- strcasecmp
- strchr
- strcmp
- strcoll
- strcspn
- strip_tags
- stripcslashes
- stripos
- stripslashes
- stristr
- strlen
- strnatcasecmp
- strnatcmp
- strncasecmp
- strncmp
- strpbrk
- strpos
- strrchr
- strrev
- strripos
- strrpos
- strspn
- strstr
- strtok
- strtolower
- strtoupper
- strtr
- substr
- substr_compare
- substr_count
- substr_replace
- trim
- ucfirst
- ucwords
- vfprintf
- vprintf
- vsprintf
- wordwrap