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));
Output for rfc.property-hooks, git.master, git.master_jit
'<h1>My Subheading</h1> <h2>My sub Subheading</h2> <h3>another heading</h3>'

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
41.08 ms | 1371 KiB | 4 Q