PHP strstr() လုပ်ဆောင်ချက်
ဥပမာ
"Hello world" အတွင်းရှိ "ကမ္ဘာ" ၏ပထမဆုံးဖြစ်ပျက်မှုကိုရှာပါ။ ပြီးလျှင် ကျန်စာကြောင်းကို ပြန်ပေးပါ။
<?php
echo strstr("Hello world!","world");
?>
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
strstr() လုပ်ဆောင်ချက်သည် အခြားသော string အတွင်းရှိ string တစ်ခု၏ ပထမဆုံး ဖြစ်ပေါ်မှုကို ရှာဖွေသည်။
မှတ်ချက်- ဤလုပ်ဆောင်ချက်သည် binary-safe ဖြစ်သည်။
မှတ်ချက်- ဤလုပ်ဆောင်ချက်သည် case-sensitive ဖြစ်သည်။ case-sensitive ရှာဖွေမှုတစ်ခုအတွက်၊ strstr() လုပ်ဆောင်ချက်ကို အသုံးပြုပါ။
အထားအသို
strstr(string,search,before_search)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
string | Required. Specifies the string to search |
search | Required. Specifies the string to search for. If this parameter is a number, it will search for the character matching the ASCII value of the number |
before_search | Optional. A boolean value whose default is "false". If set to "true", it returns the part of the string before the first occurrence of the search parameter. |
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- | ရှာဖွေရန် စာကြောင်းကို ရှာမတွေ့ပါက ကျန်စာကြောင်း (ကိုက်ညီသည့်အချက်မှ) သို့မဟုတ် FALSE ကို ပြန်ပေးသည်။ |
---|---|
PHP ဗားရှင်း- | 4+ |
ပြောင်းလဲမှုမှတ်တမ်း- | before_search parameter ကို PHP 5.3 တွင် ထည့်ထားသည် ။ |
နောက်ထပ် ဥပမာများ
ဥပမာ
"o" ၏ ASCII တန်ဖိုးအတွက် စာကြောင်းတစ်ကြောင်းကို ရှာပြီး ကျန်စာကြောင်းကို ပြန်ပေးပါ။
<?php
echo strstr("Hello world!",111);
?>
ဥပမာ
"ကမ္ဘာ" ၏ပထမဆုံးမပေါ်ပေါက်မီ စာကြောင်း၏အစိတ်အပိုင်းကို ပြန်ပေးပါ။
<?php
echo strstr("Hello world!","world",true);
?>
❮ PHP String အကိုးအကား