- array_shift: documentation ( source)
- explode: documentation ( source)
- usort: documentation ( source)
<?php
$orig = 'welcome-to-your-world-42';
//$orig = 'welcome';
$parts = explode('-', $orig);
if (1 < count($parts)) {
usort($parts, function($a, $b) { return strlen($a) < strlen($b); });
$s1 = array_shift($parts);
$s2 = array_shift($parts);
} else {
$s1 = $s2 = $orig;
}
echo $s1 . PHP_EOL . $s2;