Disallow links pointing to a given domain

In the following example, we disallow links pointing to example.org and its subdomains.

$configurator = new s9e\TextFormatter\Configurator;

$configurator->urlConfig->disallowHost('example.org');

// Test the URL config with the Autolink plugin
$configurator->Autolink;

// Get an instance of the parser and the renderer
extract($configurator->finalize());

$text = implode("\n", ['http://example.org', 'http://notexample.org', 'http://www.example.org']);
$xml  = $parser->parse($text);
$html = $renderer->render($xml);

echo $html;
http://example.org
<a href="http://notexample.org">http://notexample.org</a>
http://www.example.org

The asterisk * can be used as a joker. In the following example, we disallow links that contain "example" in their host name.

$configurator = new s9e\TextFormatter\Configurator;

$configurator->urlConfig->disallowHost('*example*');

// Test the URL config with the Autolink plugin
$configurator->Autolink;

// Get an instance of the parser and the renderer
extract($configurator->finalize());

$text = implode("\n", ['http://example.org', 'http://notexample.org', 'http://www.example.org']);
$xml  = $parser->parse($text);
$html = $renderer->render($xml);

echo $html;
http://example.org
http://notexample.org
http://www.example.org

Note that disallowing hosts does not remove the host name from the text, it only prevents linking to it. The Censor plugin can be used to censor them in plain text as well.