3v4l.org

run code in 300+ PHP versions simultaneously
<?php function splitStreetNameNumber($str) { $str = trim($str); $t = @preg_split('/[0-9]+/', $str); if (0 >= strlen($str) || 0 >= strlen(trim($t[0]))) { return false; } return array( 'name' => trim($t[0]), 'num' => trim(str_replace(trim($t[0]), '', $str)), ); } $a = array( 'Karlstr. 2', '12345', 'Karl Straße 2d', 'Karlsplatz 14 a', '', 'Karlsplatz', ); foreach($a as $b) { $c = splitStreetNameNumber($b); if (!$c) { echo 'Not a valid address.' . PHP_EOL; } else { print_r($c); } }
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [name] => Karlstr. [num] => 2 ) Not a valid address. Array ( [name] => Karl Straße [num] => 2d ) Array ( [name] => Karlsplatz [num] => 14 a ) Not a valid address. Array ( [name] => Karlsplatz [num] => )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
45.01 ms | 401 KiB | 8 Q