I'm trying to remove mailto links from the {content}, but keep the emailaddress.
Second, the @domain.tld part of each emailaddress must be a base64 string.
Example, replace
this: <a href="mailto:info@example.com">....</a>
into: info<script>eml('QGV4YW1wbGUuY29t')</__script>
The php below does work in a separate test.php file.
I'm trying to do this in an UDT but it doesn't work.
Someone can help me out here?
UDT "email_base64"
Code: Select all
$inputText = get_parameter_value($params,'text');
// get "name" part and "@domain.tld" part from email
$regex = '/<a[^(href)]+href=\"mailto:([^@]+)([^\"]+)\">[^(<\/a>)]+<\/a>/i';
// preg_replace all matches
$newText = preg_replace_callback ($regex, function ($matches) {
return $matches[1] . "<__script__>eml('" . base64_encode($matches[2]) . "')</__script>";
}, $inputText);
echo $newText;
Code: Select all
{process_pagedata}<!doctype html>
<__html>
<head>
<title>Test</title>
<__script__>{literal}
var eml = function (s) {
document.write(window.atob(s));
}
</__script>{/literal}
</head>
</__body>
{email_base64 text="{content}"}
<__body>
</__html>
Code: Select all
Replace a mailto link <a href="mailto:info@example.com">this link</a> and show part of email in base64