Due to an update to PHP7, I need to replace two rows in a plugin with preg_replace
to preg_replace_callback()
. I feel it could be simple but I have no idea how to solve it.
The original was:
for ($i = 0; $i < count($links); $i++)
{
$link = $links[$i];
if ($link['hasNum'] >= $link['maxNum']) continue;
$replace = '<a' . ($linxCSS != '' ? ' class="' . $linxCSS . '"' : '') . ' href="' . $link['href'] . '">$2</a>';
if ($linxCSS != '') $replace = '<span class="' . $linxCSS . '">' . $replace . '</span>';
$replace = '$1' . $replace . '$3';
$search = "~([\s\.\,\;\!\?\:\>\(\)\'\"\*\/«])(" . $link['words'] . ")([\*\/\'\"\(\)\<\s\.\,\;\!\?\:»])~siu";
$body = preg_replace("~(<a)(.*?)(?=<\/a>)(<\/a>)~sie", '"<:ZyX>".plgSystemSeolinks::maskContent("$1$2$3")."<:ZyX/>"', $body);
$body = preg_replace($search, $replace, $body, $link['maxNum']);
if ($body == '') return false;
$link['hasNum']+= substr_count($body, '<a ');
$links[$i] = $link;
}