Συνάρτηση str_ireplace() PHP

Παράδειγμα

Αντικατάστησε τον χαρακτήρα "WORLD" (χωρίς διάκριση γραμματοσειράς) με "Shanghai" στην αλφαβητική αλληλουσία "Hello world!":

<?php
echo str_ireplace("WORLD","Shanghai","Hello world!");
?>

Run Instances

Ορισμός και χρήση

Η συνάρτηση str_ireplace() αντικαθιστά ορισμένα χαρακτήρες της αλφαβητικής αλληλουσίας (χωρίς διάκριση γραμματοσειράς).

Η συνάρτηση πρέπει να ακολουθεί τις παρακάτω κανονισμούς:

  • Αν η αναζήτηση είναι ένας πίνακας, θα επιστρέψει έναν πίνακα.
  • Αν η αναζήτηση είναι ένας πίνακας, θα αναζητήσει και θα αντικαταστήσει σε κάθε στοιχείο του πίνακα.
  • Αν χρειάζεται να αναζητήσεις και να αντικαταστήσεις έναν πίνακα και ο αριθμός των στοιχείων που θα αντικατασταθούν είναι μικρότερος από τον αριθμό των βεβαιωμένων στοιχείων, τα επιπλέον στοιχεία θα αντικατασταθούν με κενή αλφαβητική αλληλουσία.
  • Αν αναζητάς έναν πίνακα αλλά αντικαθιστάς μόνο μια αλφαβητική αλληλουσία, η αντικατάσταση θα εφαρμόσει σε όλες τις βεβαιωμένες τιμές.

Note:This function is not case-sensitive. Please use str_replace() function to perform case-sensitive search.

Note:This function is binary safe.

Syntax

str_ireplace(find,replace,string,count)
Parameters Description
find Required. Specifies the value to be searched for.
replace Required. Specifies the replacement find The value of the value of the value.
string Required. Specifies the string to be searched.
count Optional. A variable that counts the replacement numbers.

Technical Details

Return Value: Returns a string or array with the replacement values.
PHP Version: 5+
Update Log: In PHP 5.0, a new count Parameter.

More Examples

Example 1

Use with an array and count The str_ireplace() function for variables:

<?php
$arr = array("blue","red","green","yellow");
print_r(str_ireplace("RED","pink",$arr,$i)); // This function is case-insensitive
echo "Replacement count: $i";
?>

Run Instances

Example 2

Use the str_ireplace() function with fewer elements to replace than the elements found:

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

Run Instances