<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Da testo a URL clickabile in php]]></title><description><![CDATA[<p dir="auto">ciao,<br />
vorrei trasformare tutte le url presenti in un testo in link.</p>
<p dir="auto">www . pippo . it deve trasformarsi in</p>
<pre><code class="language-php">&lt;a href="http: // www . pippo . it"&gt;www . pippo . it&lt;/a&gt;
</code></pre>
<p dir="auto">ho trovato questo codice in rete ma funziona solo se metto davanti http.</p>
<pre><code class="language-php">&lt;?php
// definizione della funzione e parametri
function testo_in_url($stringa){  
   // conversione tramite sostituzione con espressioni regolari  

   return preg_replace("~(http|https|ftp|ftps)://(.*?)(\s|\n|[,.?!](\s|\n)|$)~", "&lt;a href=\"$1://$2\" rel=\"nofollow\"&gt;$1://$2&lt;/a&gt;$3", $stringa);}
?&gt;
</code></pre>
<p dir="auto">vorrei che funzionasse sia se trovo www . pippo . it sia se trovo http: // www . pippo . it</p>
<p dir="auto">Grazie.<br />
Saluti.</p>
]]></description><link>https://dev.connect.gt/topic/148115/da-testo-a-url-clickabile-in-php</link><generator>RSS for Node</generator><lastBuildDate>Thu, 26 Nov 2026 06:46:43 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/148115.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 22 Mar 2011 17:24:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Da testo a URL clickabile in php on Wed, 23 Mar 2011 18:48:31 GMT]]></title><description><![CDATA[<p dir="auto">ok grazie.<br />
ho risolto cosi:</p>
<pre><code class="language-php">function testo_in_url($stringa){
                    // conversione tramite sostituzione con espressioni regolari
                    return preg_replace("/(www) \. (.*?)\.(([\.a-z]+))/", "&lt;a href=\"http:/ /$1.$2.$3 \" rel=\"nofollow\" &gt; $1.$2.$3 &lt;/a&gt;", $stringa);
                    
                }
</code></pre>
<p dir="auto">che dite va bene?</p>
]]></description><link>https://dev.connect.gt/post/984113</link><guid isPermaLink="true">https://dev.connect.gt/post/984113</guid><dc:creator><![CDATA[giamal84]]></dc:creator><pubDate>Wed, 23 Mar 2011 18:48:31 GMT</pubDate></item><item><title><![CDATA[Reply to Da testo a URL clickabile in php on Tue, 22 Mar 2011 19:51:21 GMT]]></title><description><![CDATA[<p dir="auto">Ciao,</p>
<p dir="auto">prova cosi:</p>
<pre><code class="language-php">function autolink($str)
{
            if (preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\&lt;]+)#i", $str, $matches))
            {
                for ($i = 0; $i &lt; count($matches['0']); $i++)
                {
                    $period = '';
                    if (preg_match("|\.$|", $matches['6'][$i]))
                    {
                        $period = '.';
                        $matches['6'][$i] = substr($matches['6'][$i], 0, -1);
                    }

                    $str = str_replace($matches['0'][$i],
                                        $matches['1'][$i].'&lt;a href="http'.
                                        $matches['4'][$i].'://'.
                                        $matches['5'][$i].
                                        $matches['6'][$i].'"&gt;http'.
                                        $matches['4'][$i].'://'.
                                        $matches['5'][$i].
                                        $matches['6'][$i].'&lt;/a&gt;'.
                                        $period, $str);
                }
            }
            return $str;
}
</code></pre>
]]></description><link>https://dev.connect.gt/post/984112</link><guid isPermaLink="true">https://dev.connect.gt/post/984112</guid><dc:creator><![CDATA[thedarkita]]></dc:creator><pubDate>Tue, 22 Mar 2011 19:51:21 GMT</pubDate></item></channel></rss>