- print_r: documentation ( source)
- preg_match_all: documentation ( source)
- preg_replace: documentation ( source)
<?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);