- str_ireplace: documentation ( source)
- preg_match_all: documentation ( source)
- str_replace: documentation ( source)
<?php
$string = "{download='text for button'} HAHA! {download='test'}";
$download = '<a class="button">Download</a>';
$search = "{download}";
if (contains($string,$search))
$string=str_ireplace($search,$download,$string);
preg_match_all("/{download='(.*?)'}/", $string, $matches, PREG_SET_ORDER);
foreach ($matches as $val) {
$string = str_replace("{download='" . $val[1] . "'}", "<a class=\"button\">" . $val[1] . "</a>", $string);
}