<?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>Penguinsoft &#187; sanitizing</title>
	<atom:link href="http://penguinsoft.us/tag/sanitizing/feed/" rel="self" type="application/rss+xml" />
	<link>http://penguinsoft.us</link>
	<description>Application Development, Web Development, Innovative Software Solutions</description>
	<lastBuildDate>Mon, 12 Mar 2012 11:14:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Sanitizing Input in Flash</title>
		<link>http://penguinsoft.us/2010/06/sanitizing-input-in-flash/</link>
		<comments>http://penguinsoft.us/2010/06/sanitizing-input-in-flash/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 00:17:38 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[Code and Servers]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[bbs]]></category>
		<category><![CDATA[characters]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[sanitizing]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://penguinsoft.us/?p=252</guid>
		<description><![CDATA[Let&#8217;s say for example you are creating a bulletin board system or some post system from within flash and you would like to restrict the use of any html or special characters. It turns out there is a very simple and elegant way you can strip out or replace any characters you want to. First ...]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say for example you are creating a bulletin board system or some post system from within flash and you would like to restrict the use of any html or special characters. <span id="more-252"></span>It turns out there is a very simple and elegant way you can strip out or replace any characters you want to.</p>
<p>First we want to declare an array in as3 with all the characters that we don&#8217;t want in our string.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> htmlChars:<span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
htmlChars<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
htmlChars<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
htmlChars<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;&amp;gt;&quot;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
htmlChars<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;&amp;lt;&quot;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;&quot;</span>;</pre></div></div>

<p>Then all we have to do is to create our function that takes a string as an argument and returns our safe sanitized string.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> sanitizeInput<span style="color: #66cc66;">&#40;</span>msg:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> htmlChar:<span style="color: #0066CC;">Object</span> <span style="color: #b1b100;">in</span> htmlChars<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
    	     msg = msg.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span>htmlChar<span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">join</span><span style="color: #66cc66;">&#40;</span>htmlChars<span style="color: #66cc66;">&#91;</span>htmlChar<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">return</span> msg;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now we can call our function.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> safeString:<span style="color: #0066CC;">String</span> = sanitizeInput<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;</span></pre></div></div>

<p>What we can also do is to replace characters in the string. For example&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">htmlChars<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Bye&quot;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;CYA&quot;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> safeString:<span style="color: #0066CC;">String</span> = sanitizeInput<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Bye for now<span style="color: #000099; font-weight: bold;">\&quot;</span>);
// safeString = &quot;</span>CYA <span style="color: #b1b100;">for</span> now<span style="color: #ff0000;">&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://penguinsoft.us/2010/06/sanitizing-input-in-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

