I have a method I use to clean up the output from user submitted data. I can pass options to either allow or disallow URLs and emails independently. I had it working fine in the past until just now when I used it with URLs disallowed and emails allowed. The problem is that the regex I use to block URLs is also blocking the domain on email addresses. How can I block URLs and domains, but only if they are not part of an email address?
My existing code;
// email address removal
if ( ! ISSET($options['email']) || $options['email'] === FALSE) {
$pattern = "/[^@\s]*@[^@\s]*\.[^@\s]*/";
$replacement = '<span class="muted">*</span>';
$string = preg_replace($pattern, $replacement, $string);
}
// url - link removal
if ( ! ISSET($options['url']) || $options['url'] === FALSE) {
$pattern = "/[a-zA-Z]*[:\/\/]*[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+/i";
$replacement = '<span class="muted">**</span>';
$string = preg_replace($pattern, $replacement, $string);
}