Unfortunatelly this algorithm is not very easy and I doubt I could even create something like that. I think it's not really worth to implement.
First of all, URLs could be the part of the hyperlink wording, for example: "mini forum could be downloaded from
miniBB site". Or URL could be "native", i.e. simply
https://www.minibb.com .
It is ok if such URL fits into first 200 preview text symbols (or whatever you specify in
$previewPostsLength). However I am sure there will be a lot of the cases, when the URL doesn't fit into limited text (so you anyway don't see it in the Preview - or you will need to increase
$previewPostsLength value to thousands, which is
for sure is not worth, since it will extremely eat your space, and won't work effective anyway).
The most difficult case is when URL
partially fits into limited length. For example first 200 symbols include
<a href="http://www.mini ... and that's all. I have no ideas how to display such URL cuts easy and effectively.
There are a lot of built-in or addon-solutions around which allow to prevent URLs in spam messages in miniBB. Why wouldn't you simply to enable them instead?
The code above absolutely works on my side. So you need just to paste one line of code, don't modify anything else - is this what you did?