I am using regex
to change plain text to url if there is http://
before the text. This works fine, but I don't want to make them a link if this link is internal
(so a link that contains my websites name)... So I only want it to happen if it is an external link.
How can I do that? I tried adding a !
before the http, but it did not work. Can someone help me out please? This is what I am using:
function wpse107488_urls_to_links( $string ) {
$string = preg_replace( "/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2", $string );
$string = preg_replace( "/([\w]+:\/\/[\w-?&;%#~=\.\/\@]+[\w\/])/i", "<a target=\"_blank\" title=\"" . __( 'Visit Site', 'your-textdomain' ) . "\" href=\"$1\">$1</a>", $string);
return $string;
}
Edit: I am using a different function that makes a link from my internal links too (that is supposed to be so), but I think these two functions are blocking each other. That's why I gave a class to all my internal links. Can I exclude them using these classes?