Skip to content

Instantly share code, notes, and snippets.

@andimariadi
Created June 1, 2017 04:19
Show Gist options
  • Select an option

  • Save andimariadi/b537494c877b02fd620d817970c8137e to your computer and use it in GitHub Desktop.

Select an option

Save andimariadi/b537494c877b02fd620d817970c8137e to your computer and use it in GitHub Desktop.
<?php
$string = 'Hai ini <a href="http://google.com">Google</a> dan ini <a href="http://pemulabelajar.com">Pemula Belajar</a>';
function plainUrls($string) {
$regex = '/https?://[^"]+/i';
if (preg_match($regex, $string, $matches)) {
return preg_replace($regex, "safelink.php?go=".base64_encode($matches[0]), $string);
} else {
return $string;
}
}
echo plainUrls($string);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment