3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = <<<TEXT == My Subheading == === My sub Subheading === ==== another heading ==== TEXT; class ContentParser { private $patterns = []; private $replacements = []; public function __construct() { $this->patterns = [ // Headings "/^==== (.+?) ====\h*$/m", "/^=== (.+?) ===\h*$/m", "/^== (.+?) ==\h*$/m", ]; $this->replacements = [ // Headings "<h3>$1</h3>", "<h2>$1</h2>", "<h1>$1</h1>", ]; } public function parse($input) { if (!empty($input)) { $output = preg_replace($this->patterns, $this->replacements, $input); } else { $output = false; // I don't recommend returning a boolean when otherwise returning strings } return $output; } } $object = new ContentParser(); var_export($object->parse($text));

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
151.48 ms | 1995 KiB | 10 Q