Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php // Split on any whitespace $words = preg_split("/\s+/", " hello world foo "); // ["", "hello", "world", "foo", ""] // Remove empty elements $words = preg_split("/\s+/", trim($text)); // Split on multiple delimiters $parts = preg_split("/[,;|]/", "a,b;c|d"); // ["a", "b", "c", "d"] // Keep the delimiter in results (PREG_SPLIT_DELIM_CAPTURE) $tokens = preg_split("/(\s+)/", "hello world", -1, PREG_SPLIT_DELIM_CAPTURE); // ["hello", " ", "world"]
Result
Open