पीएचपी preg_split () समारोह
उदाहरण
दिनांक को उसके घटकों में विभाजित करने के लिए preg_split() का उपयोग करें:
<?php
$date = "1970-01-01 00:00:00";
$pattern = "/[-\s:]/";
$components =
preg_split($pattern, $date);
print_r($components);
?>
परिभाषा और उपयोग
फ़ंक्शन विभाजक के preg_split()
रूप में नियमित अभिव्यक्ति के मैचों का उपयोग करके एक स्ट्रिंग को एक सरणी में तोड़ देता है।
वाक्य - विन्यास
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:
|
टेक्निकल डिटेल
प्रतिलाभ की मात्रा: | सबस्ट्रिंग की एक सरणी देता है जहां प्रत्येक आइटम रेगुलर एक्सप्रेशन के एक मैच द्वारा अलग किए गए इनपुट स्ट्रिंग के एक भाग से मेल खाता है |
---|---|
पीएचपी संस्करण: | 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 संदर्भ