PHP substr_count() လုပ်ဆောင်ချက်
ဥပမာ
string တွင် "ကမ္ဘာ" ဖြစ်ပေါ်သည့်အကြိမ်အရေအတွက်ကိုရေတွက်ပါ။
<?php
echo substr_count("Hello world. The world is nice","world");
?>
substr_count() လုပ်ဆောင်ချက်သည် string တစ်ခုတွင် စာကြောင်းခွဲတစ်ခု ဖြစ်ပေါ်သည့်အကြိမ်အရေအတွက်ကို ရေတွက်သည်။
မှတ်ချက်- စာတန်းခွဲသည် စာလုံးအကြီးအသေးသာဖြစ်သည်။
မှတ်ချက်- ဤလုပ်ဆောင်ချက်သည် ထပ်နေသော စာကြောင်းခွဲများကို မရေတွက်ပါ (ဥပမာ 2 ကိုကြည့်ပါ)။
မှတ်ချက်- စတင်မှုဘောင်နှင့် အရှည်ဘောင်သည် စာကြောင်းအရှည်ထက် ပိုကြီးနေပါက ဤလုပ်ဆောင်ချက်သည် သတိပေးချက်တစ်ခုထုတ်ပေးသည် (ဥပမာ 3 ကိုကြည့်ပါ)။
အထားအသို
substr_count(string,substring,start,length)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
string | Required. Specifies the string to check |
substring | Required. Specifies the string to search for |
start | Optional. Specifies where in string to start searching. If negative, it starts counting from the end of the string |
length | Optional. Specifies the length of the search |
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- | string တွင် စာကြောင်းခွဲများ ဖြစ်ပေါ်သည့် အကြိမ်အရေအတွက်ကို ပြန်ပေးသည်။ |
---|---|
PHP ဗားရှင်း- | 4+ |
ပြောင်းလဲမှုမှတ်တမ်း- | PHP 7.1 - အရှည် ဘောင်များသည် 0 သို့မဟုတ် အနှုတ်နံပါတ်တစ်ခု ဖြစ်နိုင်သည်။ PHP 7.1 - စတင်သည့် ဘောင်များသည် အနှုတ်နံပါတ်တစ်ခု ဖြစ်နိုင်သည်။ PHP 5.1 - စတင်ခြင်း နှင့် အရှည် ဘောင်များကို ထည့်သွင်းထားသည်။ |
နောက်ထပ် ဥပမာများ
ဥပမာ
ကန့်သတ်ချက်များအားလုံးကို အသုံးပြုခြင်း-
<?php
$str = "This is nice";
echo strlen($str)."<br>"; // Using strlen() to return the string length
echo substr_count($str,"is")."<br>"; // The number of times "is" occurs in the string
echo substr_count($str,"is",2)."<br>"; // The string is now reduced to "is is nice"
echo substr_count($str,"is",3)."<br>"; // The string is now reduced to "s is nice"
echo substr_count($str,"is",3,3)."<br>"; // The string is now reduced to "s i"
?>
ဥပမာ
ထပ်နေသော စာကြောင်းခွဲများ-
<?php
$str = "abcabcab";
echo substr_count($str,"abcab"); // This function does not count overlapped substrings
?>
ဥပမာ
စတင်ခြင်းနှင့် အရှည်ဘောင်များသည် စာကြောင်းအရှည်ထက် ကျော်လွန်နေပါက၊ ဤလုပ်ဆောင်ချက်သည် သတိပေးချက်ကို ထုတ်ပြန်လိမ့်မည်-
<?php
echo $str = "This is nice";
substr_count($str,"is",3,9);
?>
အရှည်တန်ဖိုးသည် စာကြောင်းအရှည်ထက် ကျော်လွန်နေသောကြောင့် ၎င်းသည် သတိပေးချက်ကို ထုတ်ပြန်လိမ့်မည် (3+9 သည် 12 ထက်ကြီးသည်)
❮ PHP String အကိုးအကား