3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Filter { protected $pattern; protected $repl; function __construct($pattern, $repl) { $this->pattern = $pattern; $this->repl = $repl; } function filter($data) { return preg_replace($this->pattern, $this->repl, $data); } }; class Post { protected $title; protected $text; protected $filters; function __construct($title, $text, $filters) { $this->title = $title; $this->text = $text; $this->filters = $filters; } function get_title() { return htmlspecialchars($this->title); } function display_post() { $text = htmlspecialchars($this->text); foreach ($this->filters as $filter) $text = $filter->filter($text); return $text; } function __destruct() { // debugging stuff $s = "<!-- POST " . htmlspecialchars($this->title); $text = htmlspecialchars($this->text); foreach ($this->filters as $filter) $text = $filter->filter($text); $s = $s . ": " . $text; $s = $s . " -->"; echo $s; } }; $standard_filter_set = [new Filter("/\[i\](.*)\[\/i\]/i", "<i>\\1</i>"), new Filter("/\[b\](.*)\[\/b\]/i", "<b>\\1</b>"), new Filter("/\[img\](.*)\[\/img\]/i", "<img src='\\1'>"), new Filter("/\[br\]/i", "<br>")]; echo serialize(new Post("hue", "br", [new Filter("/get shrekt/", "get rekt"), new Filter("/hue/", "br")] )); echo urldecode(urldecode("b%253A1%253B%2580%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2560%250AO%253A4%253A%2522Post%2522%253A3%253A%257Bs%253A8%253A%2522%252Atitle%2522%253Bs%253A3%253A%2522hue%2522%253Bs%253A7%253A%2522%252Atext%2522%253Bs%253A2%253A%2522br%2522%253Bs%253A10%253A%2522%252Afilters%2522%253Ba%253A2%253A%257Bi%253A0%253BO%253A6%253A%2522Filter%2522%253A2%253A%257Bs%253A10%253A%2522%252Apattern%2522%253Bs%253A12%253A%2522/get%2520shrekt/%2522%253Bs%253A7%253A%2522%252Arepl%2522%253Bs%253A8%253A%2522get%2520rekt%2522%253B%257Di%253A1%253BO%253A6%253A%2522Filter%2522%253A2%253A%257Bs%253A10%253A%2522%252Apattern%2522%253Bs%253A5%253A%2522/hue/%2522%253Bs%253A7%253A%2522%252Arepl%2522%253Bs%253A2%253A%2522br%2522%253B%257D%257D%257D"));
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
<!-- POST hue: br -->O:4:"Post":3:{s:8:"*title";s:3:"hue";s:7:"*text";s:2:"br";s:10:"*filters";a:2:{i:0;O:6:"Filter":2:{s:10:"*pattern";s:12:"/get shrekt/";s:7:"*repl";s:8:"get rekt";}i:1;O:6:"Filter":2:{s:10:"*pattern";s:5:"/hue/";s:7:"*repl";s:2:"br";}}}b:1;�` O:4:"Post":3:{s:8:"*title";s:3:"hue";s:7:"*text";s:2:"br";s:10:"*filters";a:2:{i:0;O:6:"Filter":2:{s:10:"*pattern";s:12:"/get shrekt/";s:7:"*repl";s:8:"get rekt";}i:1;O:6:"Filter":2:{s:10:"*pattern";s:5:"/hue/";s:7:"*repl";s:2:"br";}}}
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 <!-- POST hue: br -->O:4:"Post":3:{s:8:"*title";s:3:"hue";s:7:"*text";s:2:"br";s:10:"*filters";a:2:{i:0;O:6:"Filter":2:{s:10:"*pattern";s:12:"/get shrekt/";s:7:"*repl";s:8:"get rekt";}i:1;O:6:"Filter":2:{s:10:"*pattern";s:5:"/hue/";s:7:"*repl";s:2:"br";}}}b:1;�` O:4:"Post":3:{s:8:"*title";s:3:"hue";s:7:"*text";s:2:"br";s:10:"*filters";a:2:{i:0;O:6:"Filter":2:{s:10:"*pattern";s:12:"/get shrekt/";s:7:"*repl";s:8:"get rekt";}i:1;O:6:"Filter":2:{s:10:"*pattern";s:5:"/hue/";s:7:"*repl";s:2:"br";}}}
Output for 5.2.14 - 5.2.17, 5.3.3 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/H4mp5 on line 47
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.13, 5.3.0 - 5.3.2
Strict Standards: Redefining already defined constructor for class Filter in /in/H4mp5 on line 9 Parse error: syntax error, unexpected '[' in /in/H4mp5 on line 47
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Strict Standards: Redefining already defined constructor for class Filter in /in/H4mp5 on line 9 Parse error: parse error, unexpected '[' in /in/H4mp5 on line 47
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/H4mp5 on line 3
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_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/H4mp5 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/H4mp5 on line 3
Process exited with code 255.

preferences:
214.19 ms | 401 KiB | 312 Q