<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Didsbury Design Blog &#187; regular expressions</title>
	<atom:link href="http://blog.didsburydesign.com/tag/regular-expressions/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.didsburydesign.com</link>
	<description>Web Design and Development</description>
	<lastBuildDate>Fri, 04 Nov 2011 16:37:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to: detect URLs in text and convert to html links (PHP using regular expressions)</title>
		<link>http://blog.didsburydesign.com/2009/10/how-to-detect-urls-in-text-and-convert-to-html-links-php-using-regular-expressions/</link>
		<comments>http://blog.didsburydesign.com/2009/10/how-to-detect-urls-in-text-and-convert-to-html-links-php-using-regular-expressions/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 21:53:26 +0000</pubDate>
		<dc:creator>Didsbury Design</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[preg_replace]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[URL]]></category>
		<category><![CDATA[url detection]]></category>

		<guid isPermaLink="false">http://blog.zero7ict.com/?p=112</guid>
		<description><![CDATA[I was trying to find a way of picking up URLs from user&#8217;s posts and converting them to HTML links. I found a few examples on the net that didn&#8217;t work for multiple URLs so I thought i would post a simple solution.
I have used the PHP preg_replace function

1
2
3
4
5
6
7
8
9
10
11
&#60;?php
// The Regular Expression filter
$pattern = &#34;/(http&#124;https&#124;ftp&#124;ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/&#34;;
&#160;
//example [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying to find a way of picking up URLs from user&#8217;s posts and converting them to HTML links. I found a few examples on the net that didn&#8217;t work for multiple URLs so I thought i would post a simple solution.</p>
<p>I have used the PHP <a href="http://uk3.php.net/manual/en/function.preg-replace.php">preg_replace</a> function</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// The Regular Expression filter</span>
<span style="color: #000088;">$pattern</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//example text</span>
<span style="color: #000088;">$text</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Example user text with a URL http://www.zero7web.com , second link http://www.didsburydesign.co.uk&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// convert URLs into Links</span>
<span style="color: #000088;">$text</span><span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pattern</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>\<span style="color: #660099; font-weight: bold;">\0</span><span style="color: #000099; font-weight: bold;">\&quot;</span>?phpMyAdmin=uMSzDU7o3aUDmXyBqXX6JVQaIO3&amp;phpMyAdmin=8d6c4cc61727t4d965138r21cd rel=<span style="color: #000099; font-weight: bold;">\&quot;</span>nofollow<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;\<span style="color: #660099; font-weight: bold;">\0</span>&lt;/a&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">echo</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This will match all the URL&#8217;s in the text and not just the first one like so many of the example on the web seem to do!!</p>
<p>I will post a C# .net version of this as a follow up in the next day or so.</p>
<p>All comments welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.didsburydesign.com/2009/10/how-to-detect-urls-in-text-and-convert-to-html-links-php-using-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

