<?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>A Beautiful Blog &#187; Regular Expressions</title>
	<atom:link href="http://www.abeautifulsite.net/blog/category/regular-expressions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.abeautifulsite.net/blog</link>
	<description></description>
	<lastBuildDate>Fri, 03 Feb 2012 02:48:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>RegexPal: Develop and Test Your Regular Expressions From Your&#160;Browser</title>
		<link>http://www.abeautifulsite.net/blog/2009/03/regexpal-develop-and-test-your-regular-expressions-from-your-browser/</link>
		<comments>http://www.abeautifulsite.net/blog/2009/03/regexpal-develop-and-test-your-regular-expressions-from-your-browser/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 20:50:03 +0000</pubDate>
		<dc:creator>Cory LaViska</dc:creator>
				<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://abs.lavitech.com/?p=94</guid>
		<description><![CDATA[An online tool to help you build and test regular expressions. <a class="more-link" href="http://www.abeautifulsite.net/blog/2009/03/regexpal-develop-and-test-your-regular-expressions-from-your-browser/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p> <a href="http://regexpal.com/" rel="external">RegexPal</a> is an online regular expression tester build using JavaScript.  As you build your pattern, RegexPal offers real-time syntax highlighting, backwards/forwards context awareness, and the ability to match the part of the string that the regex pattern <em>doesn&#8217;t</em> match.  It&#8217;s also really fast. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.abeautifulsite.net/blog/2009/03/regexpal-develop-and-test-your-regular-expressions-from-your-browser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Functions to Get and Remove the File Extension from a&#160;String</title>
		<link>http://www.abeautifulsite.net/blog/2009/03/php-functions-to-get-and-remove-the-file-extension-from-a-string/</link>
		<comments>http://www.abeautifulsite.net/blog/2009/03/php-functions-to-get-and-remove-the-file-extension-from-a-string/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 00:52:22 +0000</pubDate>
		<dc:creator>Cory LaViska</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://abs.lavitech.com/?p=93</guid>
		<description><![CDATA[Two useful PHP functions to handle file names and extensions. <a class="more-link" href="http://www.abeautifulsite.net/blog/2009/03/php-functions-to-get-and-remove-the-file-extension-from-a-string/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I use these regular expressions all the time, but it&#8217;s much more convenient to have them both in convenient PHP functions.<span id="more-93"></span></p>
<h2>file_ext()</h2>
<p>Returns only the file extension (without the period).</p>
<pre class="brush: php; title: ; notranslate">function file_ext($filename) {
	if( !preg_match('/\./', $filename) ) return '';
	return preg_replace('/^.*\./', '', $filename);
}
</pre>
<h2>file_ext_strip()</h2>
<p>Returns the file name, less the extension.</p>
<pre class="brush: php; title: ; notranslate">function file_ext_strip($filename){
    return preg_replace('/\.[^.]*$/', '', $filename);
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.abeautifulsite.net/blog/2009/03/php-functions-to-get-and-remove-the-file-extension-from-a-string/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Validating File Extensions using&#160;PHP</title>
		<link>http://www.abeautifulsite.net/blog/2007/11/validating-file-extensions-using-php/</link>
		<comments>http://www.abeautifulsite.net/blog/2007/11/validating-file-extensions-using-php/#comments</comments>
		<pubDate>Wed, 07 Nov 2007 19:39:44 +0000</pubDate>
		<dc:creator>Cory LaViska</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://abs.lavitech.com/?p=44</guid>
		<description><![CDATA[A function to validate file extensions. <a class="more-link" href="http://www.abeautifulsite.net/blog/2007/11/validating-file-extensions-using-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A PHP function for validating file extensions.</p>
<p><span id="more-44"></span></p>
<h1>check_extension()</h1>
<p>Takes a string filename and checks it for a valid extension provided in  <samp>$allowed</samp>.</p>
<h3>Parameters</h3>
<table border="0">
<thead>
<tr>
<th>Argument</th>
<th>Type</th>
<th>Explanation</th>
</tr>
</thead>
<tbody>
<tr>
<td><samp>$filename</samp></td>
<td>String</td>
<td>The filename (with or without path) to be checked</td>
</tr>
<tr>
<td><samp>$allowed</samp></td>
<td>String/Array</td>
<td>A string or array containing the list of extensions that are acceptable</td>
</tr>
<tr>
<td><samp>$case_sensitive</samp></td>
<td>Boolean</td>
<td>Determines whether or not file extensions are matched in a case sensitive manner (default = false)</td>
</tr>
</tbody>
</table>
<h3>Return Values</h3>
<p>Returns <samp>true</samp> if allowed, <samp>false</samp> otherwise.</p>
<h3>Code</h3>
<pre class="brush: php; title: ; notranslate">
function check_extension($filename, $allowed = array(), $case_sensitive = false) {
    // Make sure $allowed is always an array
    if( !is_array($allowed) ) $allowed = array($allowed);

    // Determine file extension
    $file_ext = preg_replace('/^.*\./', '', $filename);

    // Handle case sensitivity
    if( !$case_sensitive ) {
        // Convert all allowed to lowercase
        foreach( array_keys($allowed) as $key ) {
            $allowed[$key] = strtolower($allowed[$key]);
        }
        // Convert file extension
        $file_ext = strtolower($file_ext);
    }

    // Check for match
    if( in_array( $file_ext, $allowed ) ) return true; else return false;
}
</pre>
<h3>Example</h3>
<pre class="brush: php; title: ; notranslate">
&lt;?php

// Single extensions example
$filename = &quot;/www/domain/some_file.txt&quot;;
$allowed = &quot;txt&quot;;
if( check_extension($filename, $allowed) ) echo &quot;TRUE&quot;; else echo &quot;FALSE&quot;;

// Multiple extensions example
$filename = &quot;/www/domain/some_file.txt&quot;;
$allowed = array(&quot;txt&quot;, &quot;csv&quot;, &quot;dat&quot;);
if( check_extension($filename, $allowed) ) echo &quot;TRUE&quot;; else echo &quot;FALSE&quot;;

?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.abeautifulsite.net/blog/2007/11/validating-file-extensions-using-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Find and Replace Hyperlinks and Email Addresses in&#160;PHP</title>
		<link>http://www.abeautifulsite.net/blog/2007/05/find-and-replace-hyperlinks-and-email-addresses-in-php/</link>
		<comments>http://www.abeautifulsite.net/blog/2007/05/find-and-replace-hyperlinks-and-email-addresses-in-php/#comments</comments>
		<pubDate>Tue, 15 May 2007 00:37:27 +0000</pubDate>
		<dc:creator>Cory LaViska</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://abs.lavitech.com/?p=12</guid>
		<description><![CDATA[PHP functions that add anchor tags around hyperlinks and email addresses in a given string. <a class="more-link" href="http://www.abeautifulsite.net/blog/2007/05/find-and-replace-hyperlinks-and-email-addresses-in-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>These two PHP functions use regular expressions to add the appropriate HTML anchor tags around hyperlinks and email addresses in <samp>$string</samp>.<span id="more-12"></span></p>
<h2>PHP Code</h2>
<pre class="brush: php; title: ; notranslate">
function parseHyperlinks($string) {
    // Add &lt;a&gt; tags around all hyperlinks in $string
    return ereg_replace(&quot;[[:alpha:]]+://[^&lt;&gt;[:space:]]+[[:alnum:]/]&quot;, &quot;&lt;a href=\&quot;\&#92;&#48;\&quot;&gt;\&#92;&#48;&lt;/a&gt;&quot;, $string);
}

function parseEmails($string) {
    // Add &lt;a&gt; tags around all email addresses in $string
    return ereg_replace(&quot;[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[A-Za-z]{2,3})&quot;, &quot;&lt;a href=\&quot;mailto:\&#92;&#48;\&quot;&gt;\&#92;&#48;&lt;/a&gt;&quot;, $string);
}
</pre>
<h2>Output</h2>
<p>Using <samp>parseHyperlinks()</samp>, <samp>http://domain.com/index.htm</samp> becomes:</p>
<pre class="brush: xml; title: ; notranslate">&lt;a href=&quot;http://domain.com/index.htm&quot;&gt;http://domain.com/index.htm&lt;/a&gt;</pre>
<p>And using <samp>parseEmails()</samp>, <samp>email@domain.com</samp> becomes:</p>
<pre class="brush: xml; title: ; notranslate">&lt;a href=&quot;mailto:email@domain.com&quot;&gt;email@domain.com&gt;&lt;/a&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.abeautifulsite.net/blog/2007/05/find-and-replace-hyperlinks-and-email-addresses-in-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

