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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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> Quote Link to comment Share on other sites More sharing options...
ionik Posted January 25, 2008 Author Share Posted January 25, 2008 works great thnx 4 help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.