PHP substr_replace() ফাংশন
প্রয়োগ
"Hello"-কে "world"-এ প্রতিস্থাপন করা হবে:
<?php echo substr_replace("Hello","world",0); ?>
সংজ্ঞা ও ব্যবহার
substr_replace() ফাংশন একটি স্ট্রিং-এর অংশকে আরেকটি স্ট্রিং-এ প্রতিস্থাপন করে
মন্তব্য:যদি start পারামিটার নেগাটিভ এবং length কম বা সমান startতবে length 0
মন্তব্য:দ্বিপদ নিরাপদ
সংজ্ঞা
substr_replace(string,replacement,start,length)
পারামিটার | বর্ণনা |
---|---|
string | আবশ্যকীয়। পরীক্ষা করা হবের জন্য নির্দিষ্ট স্ট্রিং-কে প্রদান করুন |
replacement | আবশ্যকীয়। প্রতিস্থাপন করা হবের জন্য নির্দিষ্ট স্ট্রিং-কে প্রদান করুন |
start |
আবশ্যকীয়। স্ট্রিং-এর কোথায় প্রতিস্থাপন করা হবে তা নির্দিষ্ট করে
|
length |
Optional. Specifies how many characters to replace. The default is the same as the string length.
|
Technical Details
Return Value: | Returns the replaced string. If string If it is an array, it returns an array. |
PHP Version: | 4+ |
Update Log: | Starting from PHP 4.3.3, all parameters accept arrays. |
More Examples
Example 1
Replace starting from the 6th position in the string (replace "world" with "Shanghai"):
<?php echo substr_replace("Hello world","Shanghai",6); ?>
Example 2
Replace starting from the 5th position from the end of the string (replace "world" with "Shanghai"):
<?php echo substr_replace("Hello world","Shanghai",-5); ?>
Example 3
Insert "Hello" at the beginning of "world":
<?php echo substr_replace("world","Hello ",0,0); ?>
Example 4
Replace multiple strings at once. Replace "AAA" with "BBB" in each string:
<?php $replace = array("1: AAA","2: AAA","3: AAA"); echo implode("<br>",substr_replace($replace,'BBB',3,3)); ?>