توابع str_ireplace() PHP
مثالها
رشته "Hello world!" را جایگزین میکند "WORLD" (مهم نیست که حروف بزرگ یا کوچک باشند) با "Shanghai":
<?php echo str_ireplace("WORLD","Shanghai","Hello world!"); ?>
تعریف و استفاده
توابع 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 |
string | Required. Specifies the string to be searched. |
count | Optional. A variable that counts the replacement number. |
Technical Details
Return Value: | Returns a string or array with the replacement value. |
PHP Version: | 5+ |
Update Log: | In PHP 5.0, a new count Parameters. |
More Examples
Example 1
Use with an array and count The str_ireplace() function of variables:
<?php $arr = array("blue","red","green","yellow"); print_r(str_ireplace("RED","pink",$arr,$i)); // This function is case-insensitive echo "Replacement number: $i"; ?>
Example 2
Use the str_ireplace() function with fewer elements to be replaced than the elements found:
<?php $find = array("HELLO","WORLD"); $replace = array("B"); $arr = array("Hello","world","!"); print_r(str_ireplace($find,$replace,$arr)); ?>