3v4l.org

run code in 300+ PHP versions simultaneously
<?php $articles = [ (object)['text' => 'Some text {reillorama:5/dots/1} some text {reillorama:12/foo}'], (object)['text' => 'Only text with no placeholders'], (object)['text' => 'Some text {reillorama:33} some text {reillorama:1/bar} some text'], (object)['text' => 'Some text {reillorama:5/word} some text {reillorama:2} some text {reillorama:555555/noSpacesInWord/7777777}'], (object)['text' => 'The pattern also allows the middle parameter to be omitted {reillorama:6/7}'], ]; $firstLookup = [5 => 'five', 12 => 'twelve', 1 => 'one', 2 => 'two']; $secondLookup = ['foo' => 'fighters', 'bar' => 'none', 'word' => 'up', 'noSpacesInWord' => 'replacement']; $thirdLookup = [1 => 'another one', 7 => 'seven']; foreach ($articles as $article) { $article->text = preg_replace_callback( '~{reillorama:(\d+)(?:/([a-z]+))?(?:/(\d+))?}~i', function($m) use ($firstLookup, $secondLookup, $thirdLookup) { return '**' . ($firstLookup[$m[1]] ?? '[first not found]') . ($m[2] === null ? '' : (isset($secondLookup[$m[2]]) ? $secondLookup[$m[2]] : '[second not found]')) . ($m[3] === null ? '' : (isset($thirdLookup[$m[3]]) ? $thirdLookup[$m[3]] : '[third not found]')) . '**'; //var_export($m); if you want to see what is in the matches array }, $article->text, -1, $count, PREG_UNMATCHED_AS_NULL ); echo "{$article->text}\n---\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
Some text **five[second not found]another one** some text **twelvefighters** --- Only text with no placeholders --- Some text **[first not found]** some text **onenone** some text --- Some text **fiveup** some text **two** some text **[first not found]replacement[third not found]** --- The pattern also allows the middle parameter to be omitted **[first not found]seven** ---

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:
34.82 ms | 402 KiB | 8 Q