function render(&$data) {
$data = preg_replace_callback('/(\<a.*?href.*?=.*?("|\'))(.*?)(\2.*?>)/s', 'checkUrl', $data);
return $data;
}
function checkUrl($match) {
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$protocol = 'https://';
} else {
$protocol = 'http://';
}
$full_url = $protocol.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
if ($full_url{strlen($full_url)-1}=='/') {
$full_url = substr($full_url, 0,strlen($full_url)-1);
}
$url = $_SERVER['REQUEST_URI'];
if ($url{strlen($url)-1}=='/') {
$url = substr($url, 0,strlen($url)-1);
}
if (preg_match('/^'.preg_quote($full_url,'/').'\/?$/', $match[3])||preg_match('/^'.preg_quote($url,'/').'\/?$/', $match[3])) {
return $match[1].'#'.$match[2].' onclick='.$match[2].'return false;'.$match[4];
} else {
return $match[0];
}
}
ob_start('render');
// other code
ob_end_flush();