3v4l.org

run code in 300+ PHP versions simultaneously
<?php $address = '5e Dorpsstraat 5-B'; $matchArr = array(); $matchesFound = preg_match('/(\d+)/', $address, $matchArr); if ($matchesFound === 0) { throw new TransactionValidationException('Could not find house number in address.'); } $houseNumber = array_pop($matchArr[0]); // strrpos om problemen te voorkomen bij straatnamen zoals 151th Avenue 151 $houseNumberStartPos = strrpos($address, $houseNumber); $streetName = substr($address, 0, $houseNumberStartPos); // Verwijder whitespace bij correcte notatie, geen -1 op strrpos voor foute notatie. // Voorbeeld Dorpsstraat 12 (correct), Dorpsstraat12 (incorrect). $streetName = trim($streetName); $houseNumberAdd = NULL; // Check of er mogelijk een additie is op het huisnummer, zoals B of -A of w/e. if (strlen($address) > ($houseNumberStartPos + strlen($houseNumber))) { $houseNumberAdd = substr($address, ($houseNumberStartPos + strlen($houseNumber))); $matchArr = array(); // Filter alles dat niet alfa is uit de addition field. $matchFound = preg_match('/a-Z/', $houseNumberAdd, $matchArr); if ($matchFound === 1) { $houseNumberAdd = $matchArr[0]; } } print $streetName . "\n"; print $houseNumber . "\n"; print $houseNumberAdd;
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught TypeError: array_pop(): Argument #1 ($array) must be of type array, string given in /in/INRus:9 Stack trace: #0 /in/INRus(9): array_pop('5') #1 {main} thrown in /in/INRus on line 9
Process exited with code 255.
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Warning: array_pop() expects parameter 1 to be array, string given in /in/INRus on line 9 Deprecated: strrpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /in/INRus on line 11 5e Dorpsstraat 5-B
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.32 - 7.3.33
Warning: array_pop() expects parameter 1 to be array, string given in /in/INRus on line 9 5e Dorpsstraat 5-B
Output for 5.2.0 - 5.2.17
Warning: array_pop(): The argument should be an array in /in/INRus on line 9 5e Dorpsstraat 5-B
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Warning: array_pop(): The argument should be an array in /in/INRus on line 9 0 e Dorpsstraat 5-B
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_NEW in /in/INRus on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_NEW in /in/INRus on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/INRus on line 7
Process exited with code 255.

preferences:
303.95 ms | 401 KiB | 457 Q