<?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>Make Money Blogging Tips For Free &#187; Code Snippets</title>
	<atom:link href="http://webmasterweblog.com/category/programming/code-snippets/feed" rel="self" type="application/rss+xml" />
	<link>http://webmasterweblog.com</link>
	<description>Experiences of a Webmaster</description>
	<lastBuildDate>Mon, 01 Mar 2010 13:16:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Validating a form submission</title>
		<link>http://webmasterweblog.com/validating-a-form-submission.html</link>
		<comments>http://webmasterweblog.com/validating-a-form-submission.html#comments</comments>
		<pubDate>Sat, 17 Jan 2009 20:45:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://webmasterweblog.com/?p=136</guid>
		<description><![CDATA[If you want to validate a form and you have to check if all variables are set you have to keep a few things in mind: 
a) If you disable a input field so users can only see the content you will not be able to fetch the value via $_POST
disabled=&#8221;disabled&#8221; if you add this to a input field and you submit the form you won&#8217;t be able to fetch it via $_POST
Instead use readonly=&#8221;true&#8221;
b) Textareas are slightly different. You will first have to strip all slashes if you want ...]]></description>
			<content:encoded><![CDATA[<p>If you want to validate a form and you have to check if all variables are set you have to keep a few things in mind: </p>
<p>a) If you disable a input field so users can only see the content you will not be able to fetch the value via $_POST</p>
<p><strong>disabled=&#8221;disabled&#8221; if you add this to a input field and you submit the form you won&#8217;t be able to fetch it via $_POST</strong></p>
<p><strong>Instead use readonly=&#8221;true&#8221;</strong></p>
<p>b) Textareas are slightly different. You will first have to strip all slashes if you want to fetch the real value of it. </p>
]]></content:encoded>
			<wfw:commentRss>http://webmasterweblog.com/validating-a-form-submission.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find occurences of multiple needles in haystack</title>
		<link>http://webmasterweblog.com/multiple-needles-in-haystack.html</link>
		<comments>http://webmasterweblog.com/multiple-needles-in-haystack.html#comments</comments>
		<pubDate>Fri, 17 Oct 2008 23:53:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://webmasterweblog.com/?p=111</guid>
		<description><![CDATA[Let&#8217;s say you got a form and you don&#8217;t want to allow that people submit certain words. How would you do that? Right you will have to use the PHP function strpos. Unfortunately you can&#8217;t feed strpos with arrays (a list of needles)!
Here is a very simple solution that you can use to to check multiple needles and their occurence in a specific string.

&#160;
$haystack = $myhaystack;
$needle = array&#40;'badword','badword','badword','badword'&#41;;
&#160;
foreach&#40;$needle as $value&#41;&#123;
$pos = strpos&#40;$haystack, $value&#41;;
if &#40;$pos !== false&#41;&#123; /* If we find one of those bad words do the following */
&#160;
	header&#40;&#34;Location: http://mysite.com?error=badcontent&#34;&#41;;
	exit;
&#160;
	&#125;
&#125;

I ...]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you got a form and you don&#8217;t want to allow that people submit certain words. How would you do that? Right you will have to use the PHP function strpos. Unfortunately you can&#8217;t feed strpos with arrays (a list of needles)!</p>
<p>Here is a very simple solution that you can use to to check multiple needles and their occurence in a specific string.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">&nbsp;
<span style="color: #000088;">$haystack</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$myhaystack</span>;
<span style="color: #000088;">$needle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'badword'</span><span style="color: #339933;">,</span><span style="">'badword'</span><span style="color: #339933;">,</span><span style="">'badword'</span><span style="color: #339933;">,</span><span style="">'badword'</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$needle</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$pos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$haystack</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$pos</span> <span style="color: #339933;">!==</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">/* If we find one of those bad words do the following */</span>
&nbsp;
	<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: http://mysite.com?error=badcontent&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #990000;">exit</span>;
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I used the &#8220;header&#8221; command to redirect people to a specific site if they enter those bad words. You can output a customized error message by adding a variable at the end of the URL e.g. the variable &#8220;error&#8221;. Simply retrieve the variable via GET and then echo an appropriate message. </p>
<p>If you have any question feel free to ask!</p>
<p>Enjoy <img src='http://webmasterweblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://webmasterweblog.com/multiple-needles-in-haystack.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
