ionik Posted January 24, 2008 Share Posted January 24, 2008 Ok what i have is a regex that will find all links in a text string and convert them into clickable links I.E http://website.com into <a href="http://website.com">http://website.com</a> what i need is so that will not turn links that are included in tags into clickable links Link to comment https://forums.phpfreaks.com/topic/87570-solved-find-urls-that-are-not-within-url-tags/ Share on other sites More sharing options...
effigy Posted January 24, 2008 Share Posted January 24, 2008 It usually helps to show the code in practice For starters, you can try adding (?<!url=) at the start of your pattern. Link to comment https://forums.phpfreaks.com/topic/87570-solved-find-urls-that-are-not-within-url-tags/#findComment-448180 Share on other sites More sharing options...
ionik Posted January 25, 2008 Author Share Posted January 25, 2008 im using a regex found here ~(?<!url)(??:(??:https?|ftp)://)|www\.)|\S+\@)(?:\S+\.\S+)(?<!\p{P})~ What i need is for if a url is like this [ url]http://website.com[/url] //or [ url=http://website.com]http://website.com[/url] to be excluded from the regex Link to comment https://forums.phpfreaks.com/topic/87570-solved-find-urls-that-are-not-within-url-tags/#findComment-448897 Share on other sites More sharing options...
effigy Posted January 25, 2008 Share Posted January 25, 2008 Try this: <pre> <?php $data = <<<DATA http://www.google.com [url]http://website.com[/url] [url=http://website.com]http://website.com[/url] http://www.phpfreaks.com! DATA; echo preg_replace('% ### Not preceded by an url start. (?<!url[=\]]) ( ### Protocol or start. (?: (??:https?|ftp)://) | www\. ) ### Body. (?> ### Gobble all non-space with the exception of [/url] (??!\[/url\])\S)+ ### Avoid ending punctuation. (?<!\p{P}) ) ### Not followed by an url end. (?!\[/url\]) ) %x', '<a href="$1">$1</a>', $data); ?> </pre> Link to comment https://forums.phpfreaks.com/topic/87570-solved-find-urls-that-are-not-within-url-tags/#findComment-448970 Share on other sites More sharing options...
ionik Posted January 25, 2008 Author Share Posted January 25, 2008 works great thnx 4 help Link to comment https://forums.phpfreaks.com/topic/87570-solved-find-urls-that-are-not-within-url-tags/#findComment-449279 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.