我目前有这个代码:
// turn any url into url bbcode that doesn't have it already - so we can auto link urls- thanks stackoverflow
$URLRegex = '/(?:(?<!(\[\/url\]|\[\/url=))(\s|^))'; // No [url]-tag in front and is start of string, or has whitespace in front
$URLRegex.= '('; // Start capturing URL
$URLRegex.= '(https?|ftps?|ircs?):\/\/'; // Protocol
$URLRegex.= '\S+'; // Any non-space character
$URLRegex.= ')'; // Stop capturing URL
$URLRegex.= '(?:(?<![[:punct:]])(\s|\.?$))/i'; // Doesn't end with punctuation and is end of string, or has whitespace after
$body = preg_replace($URLRegex,"$2[url=$3]$3[/url]$5", $body);
它查找任何 url,并将它们转换为 bbcode(基本上自动链接 url),问题是如果一个 / 在它的末尾,它不会被解析。
有人可以告诉我如何解决这个问题吗?谢谢!