PHP handleiding

PHP TUIS PHP Inleiding PHP installeer PHP sintaksis PHP opmerkings PHP veranderlikes PHP Echo / Druk PHP datatipes PHP Strings PHP-nommers PHP Wiskunde PHP konstante PHP-operateurs PHP As...Anders...Elseif PHP skakelaar PHP-lusse PHP funksies PHP-skikkings PHP Superglobals PHP RegEx

PHP- vorms

PHP-vormhantering PHP-vorm validering PHP-vorm word vereis PHP-vorm URL/e-pos PHP-vorm voltooi

PHP Gevorderd

PHP datum en tyd PHP sluit in PHP-lêerhantering PHP-lêer oop/lees PHP-lêer skep/skryf PHP-lêer oplaai PHP-koekies PHP-sessies PHP filters PHP-filters Gevorderd PHP-terugbelfunksies PHP JSON PHP-uitsonderings

PHP OOP

PHP Wat is OOP PHP Klasse/Objekte PHP Konstrukteur PHP vernietiger PHP Toegangswysigers PHP erfenis PHP konstante PHP Abstrakte Klasse PHP-koppelvlakke PHP eienskappe PHP statiese metodes PHP Statiese Eienskappe PHP naamruimtes PHP Iterables

MySQL- databasis

MySQL-databasis MySQL Connect MySQL Skep DB MySQL Skep tabel MySQL Voeg data in MySQL Kry Laaste ID MySQL Voeg veelvuldige in MySQL voorberei MySQL Kies Data MySQL Waar MySQL Bestel deur MySQL verwyder data MySQL-opdateringsdata MySQL-limietdata

PHP XML

PHP XML-ontleders PHP SimpleXML-ontleder PHP SimpleXML - Kry PHP XML Expat PHP XML DOM

PHP - AJAX

AJAX Intro AJAX PHP AJAX-databasis AJAX XML AJAX Live Search AJAX-peiling

PHP voorbeelde

PHP voorbeelde PHP samesteller PHP vasvra PHP Oefeninge PHP-sertifikaat

PHP- verwysing

PHP Oorsig PHP Skikking PHP-kalender PHP datum PHP gids PHP fout PHP-uitsondering PHP lêerstelsel PHP filter PHP FTP PHP JSON PHP sleutelwoorde PHP Libxml PHP-pos PHP Wiskunde PHP Diverse PHP MySQLi PHP-netwerk PHP-uitsetbeheer PHP RegEx PHP SimpleXML PHP-stroom PHP-string PHP veranderlike hantering PHP XML-ontleder PHP zip PHP Tydsones

PHP preg_split() Funksie

❮ PHP RegExp-verwysing

Voorbeeld

Gebruik preg_split() om 'n datum in sy komponente te verdeel:

<?php
$date = "1970-01-01 00:00:00";
$pattern = "/[-\s:]/";
$components = preg_split($pattern, $date);
print_r($components);
?>

Definisie en gebruik

Die preg_split()funksie breek 'n string in 'n skikking deur passings van 'n gereelde uitdrukking as skeiers te gebruik.


Sintaksis

preg_split(pattern, string, limit, flags)

Parameterwaardes

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:
  • PREG_SPLIT_NO_EMPTY - Empty strings will be removed from the returned array.
  • PREG_SPLIT_DELIM_CAPTURE - If the regular expression contains a group wrapped in parentheses, matches of this group will be included in the returned array.
  • PREG_SPLIT_OFFSET_CAPTURE - Each element in the returned array will be an array with two element, where the first element is the substring and the second element is the position of the first character of the substring in the input string.

Tegniese besonderhede

Terugkeerwaarde: Wys 'n skikking van substringe waar elke item ooreenstem met 'n deel van die invoerstring geskei deur 'n pasmaat van die gereelde uitdrukking
PHP weergawe: 4+

Meer voorbeelde

Voorbeeld

Gebruik die PREG_SPLIT_DELIM_CAPTURE vlag:

<?php
$date = "1970-01-01 00:00:00";
$pattern = "/([-\s:])/";
$components = preg_split($pattern, $date, -1,
PREG_SPLIT_DELIM_CAPTURE);
print_r($components);
?>

Voorbeeld

Gebruik die PREG_SPLIT_OFFSET_CAPTURE vlag:

<?php
$date = "1970-01-01";
$pattern = "/-/";
$components = preg_split($pattern, $date, -1,
PREG_SPLIT_OFFSET_CAPTURE);
print_r($components);
?>

❮ PHP RegExp-verwysing