3v4l.org

run code in 300+ PHP versions simultaneously
<?php function arrayToUpper($array) { return mb_strtoupper($array[0], 'UTF-8'); } function arrayToLower($array) { return mb_strtolower($array[0], 'UTF-8'); } $address_l1 = 'Ul. Tadeusza Zawadzkiego"zośki" 59/11/a 252"B"/20 "O"'; //zamieniamy znaki specjalne (tabulator, enter) na spację $first_upper = preg_replace('/([\n\r\t])/ui', ' ', trim($address_l1)); //ciąg więcej niż jedna spacja zamieniamy na jedną spację $first_upper = preg_replace('/([ ]{2,})/ui', ' ', $first_upper); //wycinamy spacje po kropkach... $first_upper = preg_replace('/(\.[ ]+)/ui', '.', $first_upper); //i wstawiamy po kropce zawsze jedną spację $first_upper = preg_replace('/(\.)/ui', '. ', $first_upper); //pierwsze litery wielkie $first_upper = mb_convert_case($first_upper, MB_CASE_TITLE, 'UTF-8'); //liczby rzymskie muszą być wszystkie wielkimi (bierzemy tylko pod uwagę liczby ze znakami I, V, X) $first_upper = preg_replace_callback('/([ \.]+[IVX-]{2,})/ui', 'arrayToUpper', " ".$first_upper); //po apostrofie mała litera $first_upper = preg_replace_callback('/([\'`].)/ui', 'arrayToLower', $first_upper); //po ukośniku duża litera $first_upper = preg_replace_callback('/([\/].)/ui', 'arrayToUpper', $first_upper); //po cudzysłowiu duża litera $first_upper = preg_replace_callback('/["].)/ui', 'arrayToUpper', $first_upper); //obcinamy spacje na początku i końcu $first_upper = trim($first_upper); var_dump($first_upper);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: preg_replace_callback(): Compilation failed: unmatched closing parenthesis at offset 4 in /in/UhgVt on line 37 Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /in/UhgVt on line 40 string(0) ""
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
Warning: preg_replace_callback(): Compilation failed: unmatched closing parenthesis at offset 4 in /in/UhgVt on line 37 string(0) ""
Output for 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 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
Warning: preg_replace_callback(): Compilation failed: unmatched parentheses at offset 4 in /in/UhgVt on line 37 string(0) ""
Output for 4.3.0 - 4.3.10
Warning: Compilation failed: unmatched parentheses at offset 4 in /in/UhgVt on line 37 string(0) ""

preferences:
311.75 ms | 401 KiB | 460 Q