PHP preg_split() လုပ်ဆောင်ချက်
ဥပမာ
ရက်စွဲတစ်ခုအား ၎င်း၏အစိတ်အပိုင်းများအဖြစ်ခွဲရန် preg_split() ကိုသုံးပါ
<?php
$date = "1970-01-01 00:00:00";
$pattern = "/[-\s:]/";
$components =
preg_split($pattern, $date);
print_r($components);
?>
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
လုပ်ဆောင်ချက်သည် ပုံမှန်အသုံးအနှုန်းတစ်ခု၏ ကိုက်ညီမှုများကို ပိုင်းခြားပေးသည့် အ preg_split()
ရာများအဖြစ် အသုံးပြုကာ string တစ်ခုအား array တစ်ခုသို့ ခွဲပေးသည်။
အထားအသို
preg_split(pattern, string, limit, flags)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
pattern | Required. A regular expression determining what to use as a separator |
string | Required. The string that is being split |
limit | Optional. Defaults to -1, meaning unlimited. Limits the number of elements that the returned array can have. If the limit is reached before all of the separators have been found, the rest of the string will be put into the last element of the array |
flags | Optional. These flags provide options to change the returned array:
|
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- | အကြောင်းအရာတစ်ခုစီသည် ပုံမှန်အသုံးအနှုန်းတစ်ခု၏ ကိုက်ညီမှုဖြင့် ပိုင်းခြားထားသော input string ၏ အစိတ်အပိုင်းတစ်ခုနှင့် သက်ဆိုင်သည့် အခင်းအကျင်းတစ်ခုစီကို ပြန်ပေးသည် |
---|---|
PHP ဗားရှင်း- | 4+ |
နောက်ထပ် ဥပမာများ
ဥပမာ
PREG_SPLIT_DELIM_CAPTURE အလံကို အသုံးပြုခြင်း-
<?php
$date = "1970-01-01 00:00:00";
$pattern = "/([-\s:])/";
$components =
preg_split($pattern, $date, -1,
PREG_SPLIT_DELIM_CAPTURE);
print_r($components);
?>
ဥပမာ
PREG_SPLIT_OFFSET_CAPTURE အလံကို အသုံးပြုခြင်း-
<?php
$date = "1970-01-01";
$pattern = "/-/";
$components =
preg_split($pattern, $date, -1,
PREG_SPLIT_OFFSET_CAPTURE);
print_r($components);
?>
❮ PHP RegExp အကိုးအကား