PHP preg_filter() လုပ်ဆောင်ချက်
ဥပမာ
ကြိုးများစာရင်းတွင် နံပါတ်များကို ကွင်းစကွင်းပိတ်ဖြင့် ခြုံပါ-
<?php
$input = [
"It is 5 o'clock",
"40 days",
"No
numbers here",
"In the year 2000"
];
$result =
preg_filter('/[0-9]+/', '($0)', $input);
print_r($result);
?>
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
လုပ်ဆောင်ချက်သည် ပုံစံ ၏ preg_filter()
ကိုက်ညီမှုများကို အစားထိုးထားသောစာကြောင်းဖြင့် အစားထိုးထားသည့် စာကြောင်းတစ်ကြောင်း သို့မဟုတ် အခင်းအကျင်းတစ်ခုကို ပြန်ပေးသည်။
input သည် array ဖြစ်ပါက၊ ဤ function သည် array ကို return ပြန်သည် ။ input သည် string ဖြစ်ပါက၊ ဤ function သည် string တစ်ခုကို ပြန်ပေးသည်။
ဤလုပ်ဆောင်ချက်သည် ခြားနားချက်တစ်ခုနှင့် ဆင်တူသည် preg_replace()
- input string တစ်ခုတွင် ပုံစံအတွက် ကိုက်ညီမှုတစ်ခုကို ရှာမတွေ့သောအခါ၊ string ကို return value တွင် အသုံးပြုမည်မဟုတ်ပါ။ ဤအခြေအနေတွင်၊ ထည့်သွင်းမှုသည် array အစား စာကြောင်းတစ်ကြောင်းဖြစ်ပါက၊ လုပ်ဆောင်ချက်သည် null ဖြစ်သွားသည် ။
အစားထိုးထားသောစာကြောင်းများတွင် ပုံစံအကိုးအကားများ \n သို့မဟုတ် $n သည် ပုံစံရှိ အုပ်စုတစ်ခု၏ အညွှန်းများပါ၀င်နိုင်သည်။ ပြန်ပေးထားသောစာကြောင်းတွင်၊ \n နှင့် $n ၏ဥပမာများကို အဖွဲ့မှလိုက်ဖက်သောစာကြောင်းခွဲဖြင့် အစားထိုးမည် သို့မဟုတ် \0 သို့မဟုတ် $0 ကို အသုံးအနှုန်းတစ်ခုလုံးဖြင့် အသုံးပြုပါက၊
အထားအသို
preg_filter(pattern, replacement, input, limit, count)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
pattern | Required. Contains a regular expression indicating what to search for |
replacement | Required. A string which will replace the matched patterns. It may contain backreferences |
input | Required. A string or array of strings in which the replacements are being performed |
limit | Optional. Defaults to -1, meaning unlimited. Sets a limit to how many replacements can be done in each string |
count | Optional. After the function has executed, this variable will contain a number indicating how many replacements were performed |
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- | input သည် array တစ်ခုဖြစ်ခဲ့လျှင် အစားထိုးထားသော string များကို ပြန်ပေးသည်၊၊ input သည် string သို့မဟုတ် null ဖြစ်လျှင် input သည် string တစ်ခုဖြစ်ပြီး ကိုက်ညီမှုမရှိပါက အစားထိုးထားသော string တစ်ခုအား ပြန်ပေးသည် |
---|---|
PHP ဗားရှင်း- | ၅.၃.၀ |
❮ PHP RegExp အကိုးအကား