PHP str_ireplace() ফাংশন
উদাহরণ
স্ট্রিং "Hello world!"-এর "WORLD" (বৈচিত্র্যহীন) অক্ষরকে "Shanghai"-এ প্রতিস্থাপন করো:
<?php echo str_ireplace("WORLD","Shanghai","Hello world!"); ?>
সংজ্ঞা ও ব্যবহার
str_ireplace() ফাংশন স্ট্রিংয়ের কিছু অক্ষরকে (বৈচিত্র্যহীন) প্রতিস্থাপন করে。
এই ফাংশনটি নিম্নলিখিত নিয়মগুলি অনুসরণ করতে হবে:
- যদি অনুসন্ধান করা হওয়া স্ট্রিং একটি অ্যারে, তবে এটি একটি অ্যারে ফিরিয়ে দেবে。
- যদি অনুসন্ধান করা হওয়া স্ট্রিং একটি অ্যারে, তবে এটি অ্যারের প্রত্যেক ইলাকায় অনুসন্ধান ও প্রতিস্থাপন করবে。
- যদি একইসঙ্গে অ্যারের জন্য অনুসন্ধান ও প্রতিস্থাপন করা হয়, এবং প্রতিস্থাপন করা হওয়া ইলাকার সংখ্যা অনুসন্ধান করা হওয়া ইলাকার সংখ্যা থেকে কম, তবে অতিরিক্ত ইলাকা ক্রিয়াহীন স্ট্রিং-দ্বারা প্রতিস্থাপিত হবে。
- যদি একটি অ্যারের জন্য অনুসন্ধান করা হয়, কিন্তু শুধুমাত্র একটি স্ট্রিংকে প্রতিস্থাপন করা হয়, তবে প্রতিস্থাপন করা হওয়া স্ট্রিং সব পাওয়া মানকেই কাজে লাগবে。
Comments:This function is not case-sensitive. Please use str_replace() Function to perform case-sensitive search.
Comments: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 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 Parameter. |
More Examples
Example 1
Use with arrays and count 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 count: $i"; ?>
Example 2
Use 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)); ?>