Example 1 — Split on Whitespace
Cut a sentence into words using a whitespace pattern.
<?php
$parts = preg_split('/\s+/', 'one two three');
print_r($parts); How It Works
- The pattern /\s+/ matches one or more spaces.
- Multiple spaces count as a single delimiter.
- The string becomes three words.
- print_r() shows the resulting array.

