3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function dataFromUrl($url) { $url = trim($url); if (!preg_match('@^data:[^,;]*+(?>\s*+;\s*+[^=,;]++\s*+=\s*+[^,;]*+\s*+)*+\s*+(?<type>;\s*+base64\s*+,\s*+|,)(?<data>.*)$@ADis', $url, $m)) { throw new \Exception('Bar data URL.'); } $data = rawurldecode($m['data']); if (($m['type'] ?? '') !== ',') $data = base64_decode($data); return $data; } var_dump(dataFromUrl('data:text/plain;charset=utf-8;base64,SGVsbG8gd29ybGQh')) . PHP_EOL; var_dump(dataFromUrl('data:text/plain ; charset = utf-8 ; base64, SGVsbG8gd29ybGQh')) . PHP_EOL; var_dump(dataFromUrl('data:; charset = utf-8 ; base64, SGVsbG8gd29ybGQh')) . PHP_EOL; var_dump(dataFromUrl('data:;base64 , SGVsbG8gd29ybGQh')) . PHP_EOL; var_dump(dataFromUrl('data:;base64 , SGVsbG8gd29ybGQh')) . PHP_EOL; var_dump(dataFromUrl('data:text/plain;charset=utf-8,Hello%20world%21')) . PHP_EOL;
Output for hhvm-3.18.4 - 3.21.0, 7.0.0 - 7.2.11
string(12) "Hello world!" string(12) "Hello world!" string(12) "Hello world!" string(12) "Hello world!" string(12) "Hello world!" string(12) "Hello world!"
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected '?' in /in/tou79 on line 9
Process exited with code 255.