PHP substr_replace() လုပ်ဆောင်ချက်
ဥပမာ
"Hello" ကို "world" ဖြင့် အစားထိုးပါ။
<?php
echo substr_replace("Hello","world",0);
?>
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
substr_replace() လုပ်ဆောင်ချက်သည် စာကြောင်းတစ်ခု၏ အစိတ်အပိုင်းတစ်ခုကို အခြားစာကြောင်းတစ်ခုဖြင့် အစားထိုးသည်။
မှတ်ချက် ။
မှတ်ချက်- ဤလုပ်ဆောင်ချက်သည် binary-safe ဖြစ်သည်။
အထားအသို
substr_replace(string,replacement,start,length)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
string | Required. Specifies the string to check |
replacement | Required. Specifies the string to insert |
start | Required. Specifies where to start replacing in the string
|
length | Optional. Specifies how many characters should be replaced. Default is the same length as the string.
|
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- | အစားထိုးထားသော စာကြောင်းကို ပြန်ပေးသည်။ string သည် array ဖြစ်လျှင် array ကို ပြန်ပေးသည်။ |
---|---|
PHP ဗားရှင်း- | 4+ |
ပြောင်းလဲမှုမှတ်တမ်း- | PHP 4.3.3 အရ၊ ဘောင်များအားလုံးသည် ယခု arrays ကို လက်ခံပါသည်။ |
နောက်ထပ် ဥပမာများ
ဥပမာ
ကြိုးတန်းရှိ 6th အနေအထားတွင် စတင် ("ကမ္ဘာ" ကို "မြေကြီး" ဖြင့် အစားထိုးပါ):
<?php
echo substr_replace("Hello world","earth",6);
?>
ဥပမာ
string ၏အဆုံးမှ 5th အနေအထားတွင် စတင် အစားထိုးခြင်း ( "world" ကို "earth" ဖြင့် အစားထိုးပါ):
<?php
echo substr_replace("Hello world","earth",-5);
?>
ဥပမာ
"ကမ္ဘာ" ၏အစတွင် "Hello" ကိုထည့်ပါ။
<?php
echo substr_replace("world","Hello ",0,0);
?>
ဥပမာ
လိုင်းများစွာကို တစ်ပြိုင်နက် အစားထိုးပါ။ စာကြောင်းတစ်ခုစီတွင် "AAA" ကို "BBB" ဖြင့် အစားထိုးပါ။
<?php
$replace = array("1: AAA","2: AAA","3: AAA");
echo implode("<br>",substr_replace($replace,'BBB',3,3));
?>
❮ PHP String အကိုးအကား