Here's an attempted solution that relies on $_SERVER['HTTP_HOST']
:
function targetBlank($text) {
if( strpos( $text, $_SERVER['HTTP_HOST'] ) === false )
return str_replace('
Untested, but it should work. @meager is also correct in that this will produce malformed anchor tags if that tag already has a target defined, however, since it will only operate on html strings that you pass in, then
and so on should be safe as long as you only pass strings with anchor tags in them.