Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $text = $_GET['text'];
- $blacklist = preg_split('/[*\s]+/', $_GET['blacklist'], -1, PREG_SPLIT_NO_EMPTY);
- $emailPattern = "/\b([\w+-]+)@([A-Za-z0-9-]+)\.([A-Za-z0-9.-]+)\b/";
- if (preg_match_all($emailPattern, $text, $matches)) {
- $fullEmails = $matches[0];
- $domainParts = $matches[3];
- foreach ($fullEmails as $key => $email) {
- $domain = $domainParts[$key];
- $isBlackListed = false;
- if (in_array($email, $blacklist)) {
- $isBlackListed = true;
- } else {
- foreach ($blacklist as $blacklisted) {
- if ($blacklisted[0] == '.' && (strpos($blacklisted, $domain) === 1)
- ) {
- $isBlackListed = true;
- break;
- }
- }
- }
- if ($isBlackListed) {
- $replacement = str_repeat('*', strlen($email));
- } else {
- $replacement = '<a href="mailto:' . $email . '">' . $email . '</a>';
- }
- $text = str_replace($email, $replacement, $text);
- }
- }
- ?>
- <p><?= $text ?></p>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement