3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "we have a card [mtgcard]tarmogoyf[/mtgcard] "; $string .= "and [mtgcard]forest[/mtgcard] "; $string = preg_replace('/\[mtgcard\](.*?)\[\/mtgcard\]/', '<a href="https://deckbox.org/mtg/$1">$1</a>', $string); echo $string; $string = "we have a card [mtgcard]tarmogoyf[/mtgcard] "; $string .= "and [mtgcard]forest[/mtgcard] "; preg_match_all('/\[mtgcard\](.*?)\[\/mtgcard\]/', $string, $matches); $arr = $matches[1]; foreach ($arr as &$a) { $a = "<a href=\"https://deckbox.org/mtg/$a\">$a</a>"; } print_r($arr);

preferences:
25.01 ms | 406 KiB | 5 Q