Pergunta

OK, I've been using the following code to find any URLS in the text that I enter, but some things like YouTube code or whatnot have links in them and it finds those as well. I would like to have this code modified so that it ignores quotes around the links that are already a part of something.

`public function auto_link_text($text) {

    $pattern  = '#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#';
    return preg_replace_callback($pattern, array($this, 'auto_link_text_callback'), $text);

}`
Foi útil?

Solução

This just excludes links preceded by a quotation mark

/(?<=[^"]|^)(https?|ftp|file):\/\/[-a-zA-Z0-9+&@#\/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#\/%=~_|]/
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top