<?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>Paul Cracknell &#187; PHP MySQL Tips</title>
	<atom:link href="http://paulcracknell.net/category/php-mysql-tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://paulcracknell.net</link>
	<description>Website development</description>
	<lastBuildDate>Mon, 20 May 2013 11:09:05 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>PHP to limit a text string to a number of words</title>
		<link>http://paulcracknell.net/1125/php-to-limit-a-text-string-to-a-number-of-words/</link>
		<comments>http://paulcracknell.net/1125/php-to-limit-a-text-string-to-a-number-of-words/#comments</comments>
		<pubDate>Mon, 20 May 2013 11:09:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP MySQL Tips]]></category>

		<guid isPermaLink="false">http://paulcracknell.net/?p=1125</guid>
		<description><![CDATA[Recently I had cause to show an excerpt of information which would then link to another page for the complete article. I had to show a limited number of words from the entire article as a teaser. I managed to do this with a little function. &#160; function limit_words&#40;$string, $word_limit&#41; &#123; $words = explode&#40;&#34; &#34;,$string&#41;; [...]]]></description>
				<content:encoded><![CDATA[<p>Recently I had cause to show an excerpt of information which would then link to another page for the complete article. I had to show a limited number of words from the entire article as a teaser. I managed to do this with a little function.</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> limit_words<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$word_limit</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$words</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">array_splice</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$word_limit</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>You call the function from your page page with this.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;I wanted to show this function in all its glory and have been able to do this.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> limit_words<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This will show the first seven words.</p>
<p>&#8220;I wanted to show this function in&#8221;</p>
<p>Change the number to whatever suits you.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulcracknell.net/1125/php-to-limit-a-text-string-to-a-number-of-words/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPmyAdmin importing csv file to MySql database</title>
		<link>http://paulcracknell.net/1032/phpmyadmin-importing-csv-file-to-mysql-database/</link>
		<comments>http://paulcracknell.net/1032/phpmyadmin-importing-csv-file-to-mysql-database/#comments</comments>
		<pubDate>Sun, 02 Dec 2012 11:26:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP MySQL Tips]]></category>
		<category><![CDATA[phpmyadmin]]></category>

		<guid isPermaLink="false">http://www.paulcracknell.net/?p=1032</guid>
		<description><![CDATA[This is pretty easy once you work out a couple of the idiosyncrasies involved in the process. These are my tips to help if you are experiencing difficulties. 1. When you develop your excel file save it out as a csv file. This means do not save it as a work book or any other [...]]]></description>
				<content:encoded><![CDATA[<p>This is pretty easy once you work out a couple of the idiosyncrasies involved in the process. These are my tips to help if you are experiencing difficulties.</p>
<p>1. When you develop your excel file save it out as a csv file. This means do not save it as a work book or any other format. When it has been saved take a look at it with a text reader such as notepad or similar. You will probably notice that each column is separated by a comma (,). This is important when we look at importing the file with PHPmyAdmin.</p>
<p>2. Cleanse your CSV file. Get rid of column headings. Ensure that there is an entry of some form in each row and column. Get rid of blank areas.</p>
<p>3. You must ensure that the table you are importing your data into is represented identically in the CSV file. This means that if your table has 10 columns you must have 10 corresponding columns in your CSV file. There is one exception to this however, if your first column is an id autoincrement column this does not need to be one of the included columns in your CSV. For example if you have a table structure like this:</p>
<p>MySql Table: Competitors<br />
id,eventID,imageID,raceNumber,firstName,lastName,raceTime,category,<br />
catPosition,gender,cap</p>
<p>CSV File:<br />
eventID,imageID,raceNumber,firstName,lastName,raceTime,category,<br />
catPosition,gender,cap</p>
<p>The id column is not represented in the CSV file.</p>
<p>4. If you do not have data for some of the columns in the CSV file enter 0 for each line.</p>
<p>5. In PHPmyAdmin click on the import tab. Click on the browse button and select your csv file. It will automatically select the CSV in Format or Imported File area.</p>
<p>6. In the Format of Imported File area:</p>
<p>Fields terminated by ,<br />
Fields enclosed by (leave blank)<br />
Fields escaped by<br />
Lines terminated by auto<br />
Column names eventID,imageID,raceNumber,firstName,lastName,raceTime,category,<br />
catPosition,gender,cap (this is the example above used again here)</p>
<p>7. The category names above are separated by a comma (,) and there are no spaces after or before each word.</p>
<p>8. Click on Go</p>
<p>If everything went well you should have a fully populated table.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulcracknell.net/1032/phpmyadmin-importing-csv-file-to-mysql-database/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Here Doc</title>
		<link>http://paulcracknell.net/1011/php-here-doc/</link>
		<comments>http://paulcracknell.net/1011/php-here-doc/#comments</comments>
		<pubDate>Mon, 05 Nov 2012 21:50:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP MySQL Tips]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.paulcracknell.net/?p=1011</guid>
		<description><![CDATA[The Here Doc is most useful when you have a long string with many double quotes that need to be escaped by a backslash. $pix .= &#40;&#34;&#60;li&#62;&#60;input type=&#34;checkbox&#34; name=&#34;picture&#91;&#93;&#34; value=&#34;'. $root.$dir.' '.$file.'&#34; /&#62; Value One&#60;/li&#62;&#34;&#41;; The same string with a &#8220;Here Doc&#8221;. $pix = &#60;&#60;&#60;END (&#34;&#60;li&#62;&#60;input type=&#34;checkbox&#34; name=&#34;picture[]&#34; value=&#34;'. $root.$dir.' '.$file.'&#34; /&#62; Value One&#60;/li&#62;&#34;) END; [...]]]></description>
				<content:encoded><![CDATA[<p>The Here Doc is most useful when you have a long string with many double quotes that need to be escaped by a backslash.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$pix</span> <span style="color: #339933;">.=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;li&gt;&lt;input type=&quot;</span>checkbox<span style="color: #0000ff;">&quot; name=&quot;</span>picture<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #0000ff;">&quot; value=&quot;</span><span style="color: #0000ff;">'. $root.$dir.'</span> <span style="color: #0000ff;">'.$file.'</span><span style="color: #0000ff;">&quot; /&gt;
Value One&lt;/li&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The same string with a &#8220;Here Doc&#8221;.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$pix</span> <span style="color: #339933;">=</span> <span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;END
(&quot;&lt;li&gt;&lt;input type=&quot;checkbox&quot; name=&quot;picture[]&quot; value=&quot;'. $root.$dir.' '.$file.'&quot; /&gt;
Value One&lt;/li&gt;&quot;)
END</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>To use Here Doc you need to start with <<< followed by any word or string of letters, numbers or underscors as long as it does not start with a number. In the example I have used END.</p>
<p>The string must start on a new line after you have started the Here Doc. Variables will be read without he need to put quotes around them.</p>
<p>The end identifier needs to start at the start of a new line and have no white space before it otherwise it will cause an error. You can&#8217;t even tab it in. The semicolon is allowable at the end.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulcracknell.net/1011/php-here-doc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP loading multiple checkbox input into separate rows in MySql</title>
		<link>http://paulcracknell.net/1005/php-loading-multiple-checkbox-input-into-separate-rows-in-mysql/</link>
		<comments>http://paulcracknell.net/1005/php-loading-multiple-checkbox-input-into-separate-rows-in-mysql/#comments</comments>
		<pubDate>Thu, 01 Nov 2012 21:27:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP MySQL Tips]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.paulcracknell.net/?p=1005</guid>
		<description><![CDATA[Some time back now, in an image gallery I was developing, I had a folder with images the directory that had not been added to the database. To add the selected images by the user I decided to use checkboxes. Each selected box represented the path to where the images was stored. This is the [...]]]></description>
				<content:encoded><![CDATA[<p>Some time back now, in an image gallery I was developing, I had a folder with images the directory that had not been added to the database.  To add the selected images by the user I decided to use checkboxes.  Each selected box represented the path to where the images was stored.  This is the code I used to call the images and display them with a check box. I used a foreach loop for this purpose.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">// Takes the submitted info from the form FOLDER and make variables so we can display images.</span>
            <span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'folder'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//The user selects the relevant folder from a previous form</span>
            <span style="color: #000088;">$root</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'gallery/'</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$files</span> <span style="color: #339933;">=</span> <span style="color: #990000;">scandir</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$root</span><span style="color: #006699; font-weight: bold;">$dir</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                
&nbsp;
                   <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$files</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">==</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">||</span><span style="color: #000088;">$file</span> <span style="color: #339933;">==</span><span style="color: #0000ff;">'..'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//get rid of directory dots . ..</span>
                      <span style="color: #339933;">@</span><span style="color: #000088;">$pix</span> <span style="color: #339933;">.=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;li&gt;&lt;input type=&quot;</span>checkbox<span style="color: #0000ff;">&quot; name=&quot;</span>picture<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #0000ff;">&quot; value=&quot;</span><span style="color: #0000ff;">&quot;. <span style="color: #006699; font-weight: bold;">$root</span>.<span style="color: #006699; font-weight: bold;">$dir</span>.&quot;</span><span style="color: #339933;">/</span><span style="color: #0000ff;">&quot;.<span style="color: #006699; font-weight: bold;">$file</span>.&quot;</span><span style="color: #0000ff;">&quot; /&gt;
                      &lt;a href=&quot;</span><span style="color: #0000ff;">&quot;. <span style="color: #006699; font-weight: bold;">$root</span>.<span style="color: #006699; font-weight: bold;">$dir</span>.&quot;</span><span style="color: #339933;">/</span><span style="color: #0000ff;">&quot; . <span style="color: #006699; font-weight: bold;">$file</span> .&quot;</span><span style="color: #0000ff;">&quot; rel=&quot;</span>lightbox<span style="color: #009900;">&#91;</span>set<span style="color: #009900;">&#93;</span><span style="color: #0000ff;">&quot;&gt;
                      &lt;img src=&quot;</span><span style="color: #0000ff;">&quot;. <span style="color: #006699; font-weight: bold;">$root</span>.<span style="color: #006699; font-weight: bold;">$dir</span>.&quot;</span><span style="color: #339933;">/</span><span style="color: #0000ff;">&quot; . <span style="color: #006699; font-weight: bold;">$file</span> .&quot;</span><span style="color: #0000ff;">&quot; alt=&quot;</span><span style="color: #0000ff;">&quot;.<span style="color: #006699; font-weight: bold;">$file</span>.&quot;</span><span style="color: #0000ff;">&quot;&gt;&lt;/a&gt;&lt;/li&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                   <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If multiple images were selected an array for picture[] was created.  If this was inserted directly into the database only the last item will be stored in the database. So it is necessary to run through the array and insert each item in its own row within the databse.  I used another foreach loop for this task. Here is the code.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
 <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//This is a number for the user </span>
 <span style="color: #000088;">$pix</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'picture'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//This is the array of items from the post of the previous script.</span>
&nbsp;
&nbsp;
 <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$pix</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$pic</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #000088;">$result</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO urls (id, id_key, url, date) VALUES ('', '<span style="color: #006699; font-weight: bold;">$name</span>', '<span style="color: #006699; font-weight: bold;">$pic</span>', NOW())&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The foreach command will cycle through the array until the last record is reached.  Not knowing how many records would be selected this works extremely well.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulcracknell.net/1005/php-loading-multiple-checkbox-input-into-separate-rows-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validating an email address with PHP</title>
		<link>http://paulcracknell.net/1000/validating-an-email-address-with-php/</link>
		<comments>http://paulcracknell.net/1000/validating-an-email-address-with-php/#comments</comments>
		<pubDate>Tue, 30 Oct 2012 09:59:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP MySQL Tips]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.paulcracknell.net/?p=1000</guid>
		<description><![CDATA[Dodgy email addresses from people can be a problem but not any more with this little function that checks an email address with regular expression. Here is the code, call it from within your script. &#160; $checkEmail = info@example.com echo validEmail&#40;$checkEmail&#41;; &#160; function validEmail&#40;$email&#41;&#123; &#160; // Valid Email address Regular expression // No spaces in [...]]]></description>
				<content:encoded><![CDATA[<p>Dodgy email addresses from people can be a problem but not any more with this little function that checks an email address with regular expression.  Here is the code, call it from within your script.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000088;">$checkEmail</span> <span style="color: #339933;">=</span> info<span style="color: #339933;">@</span>example<span style="color: #339933;">.</span>com
<span style="color: #b1b100;">echo</span> validEmail<span style="color: #009900;">&#40;</span><span style="color: #000088;">$checkEmail</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> validEmail<span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Valid Email address Regular expression</span>
		<span style="color: #666666; font-style: italic;">// No spaces in pattern either</span>
		<span style="color: #000088;">$pattern</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'/^S+@S+.S+$/'</span><span style="color: #339933;">;</span> 
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pattern</span><span style="color: #339933;">,</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$badEmail</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'The email address does not appear to be correct.'</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$badEmail</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>You can tweek it to suit your needs.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulcracknell.net/1000/validating-an-email-address-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using PHP for password validation</title>
		<link>http://paulcracknell.net/996/using-php-for-password-validation/</link>
		<comments>http://paulcracknell.net/996/using-php-for-password-validation/#comments</comments>
		<pubDate>Mon, 29 Oct 2012 10:45:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP MySQL Tips]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.paulcracknell.net/?p=996</guid>
		<description><![CDATA[Passwords are a necessary evil these days, almost every site you go to now, you have the ability to register with them which requires a password. I have a function that I use for checking that the password meets my minimum standards to ensure the security of the users information. This is the code. function [...]]]></description>
				<content:encoded><![CDATA[<p>Passwords are a necessary evil these days, almost every site you go to now, you have the ability to register with them which requires a password.  I have a function that I use for checking that the password meets my minimum standards to ensure the security of the users information.  This is the code.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> validPassword<span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//Empty error array for the errors if any</span>
	<span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Password Strength check</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">6</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$error</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Password need to have at least 6 characters!'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">20</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$error</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Password needs to have less than 20 characters!'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#[0-9]+#&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$error</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Password must include at least one number!'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#[a-z]+#&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$error</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Password must include at least one letter!'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#[A-Z]+#&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$error</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Password must include at least one uppercase letter!'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// Make the array readable</span>
				<span style="color: #000088;">$errors</span><span style="color: #339933;">=</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">return</span> <span style="color: #000088;">$errors</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This is how you call it on the relevant page.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// You would give the variable value from the $_POST['Pa55w*rd'] really!!</span>
<span style="color: #666666; font-style: italic;">//This is an example though so here it is simply.</span>
<span style="color: #000088;">$pw</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Pa55w*rd'</span><span style="color: #339933;">;</span>
&nbsp;
validPassword<span style="color: #009900;">&#40;</span><span style="color: #000088;">$pw</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>Of course you can change each condition as you see fit and not all conditions need to be kept either.  Hope this is useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulcracknell.net/996/using-php-for-password-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP convert date yyyy-mm-dd to dd-mm-yyyy</title>
		<link>http://paulcracknell.net/983/php-convert-date-yyyy-mm-dd-to-dd-mm-yyyy/</link>
		<comments>http://paulcracknell.net/983/php-convert-date-yyyy-mm-dd-to-dd-mm-yyyy/#comments</comments>
		<pubDate>Sun, 28 Oct 2012 12:49:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP MySQL Tips]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.paulcracknell.net/?p=983</guid>
		<description><![CDATA[Dates that come from MySql databases are a bit back to front for people to read.  The year first followed by months and then days.  In Australia, New Zealand, Europe and many other countries it is dd-mm-yyyy so this is a small function to turn this around to be more readable. On your page where [...]]]></description>
				<content:encoded><![CDATA[<p>Dates that come from MySql databases are a bit back to front for people to read.  The year first followed by months and then days.  In Australia, New Zealand, Europe and many other countries it is dd-mm-yyyy so this is a small function to turn this around to be more readable.</p>
<p>On your page where you call the date from the datbase, put the date into a variable then call the function.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//This is the function</span>
<span style="color: #000000; font-weight: bold;">function</span> changeDate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$backwardsDate</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$newDate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;d-m-Y&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$backwardsDate</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$newDate</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This is the code on the relevant page.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Put the date into a variable</span>
<span style="color: #000088;">$backwardsDate</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2012</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">28</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//Call the function</span>
<span style="color: #b1b100;">echo</span> changeDate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$backwardsDate</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Once processed by the function it will output </span>
<span style="color: #666666; font-style: italic;">// 28-10-2012</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://paulcracknell.net/983/php-convert-date-yyyy-mm-dd-to-dd-mm-yyyy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP compare dates to determine if one is expired</title>
		<link>http://paulcracknell.net/964/php-compare-dates-to-determine-if-one-is-expired/</link>
		<comments>http://paulcracknell.net/964/php-compare-dates-to-determine-if-one-is-expired/#comments</comments>
		<pubDate>Sat, 27 Oct 2012 11:49:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP MySQL Tips]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.paulcracknell.net/?p=964</guid>
		<description><![CDATA[Here is a PHP fuction that I have used recently to calculate if an album in a gallery is expired. This is what goes in the html. 1 2 3 4 //Define the album date in a variable $albumDate = 2012-11-01; //Call to function albumExpired&#40;$albumDate&#41;; This is the function which is called. 1 2 3 [...]]]></description>
				<content:encoded><![CDATA[<p>Here is a PHP fuction that I have used recently to calculate if an album in a gallery is expired.</p>
<p>This is what goes in the html.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Define the album date in a variable</span>
<span style="color: #000088;">$albumDate</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2012</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">11</span><span style="color: #339933;">-</span><span style="color: #208080;">01</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//Call to function</span>
albumExpired<span style="color: #009900;">&#40;</span><span style="color: #000088;">$albumDate</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This is the function which is called.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//  Show expired albums</span>
<span style="color: #000000; font-weight: bold;">function</span> albumExpired<span style="color: #009900;">&#40;</span><span style="color: #000088;">$expiry</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Find todays date.</span>
		<span style="color: #000088;">$today</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">//Change date into a string</span>
		<span style="color: #000088;">$todaysDate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$today</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">// Change the album date into a string</span>
		<span style="color: #000088;">$expiryDate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$expiry</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">// compare the two dates (strings)</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$expiryDate</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$todaysDate</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'Expired'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'Not Expired'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://paulcracknell.net/964/php-compare-dates-to-determine-if-one-is-expired/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Warning: mysqli_query() [function.mysqli-query]: Couldn&#8217;t fetch mysqli in</title>
		<link>http://paulcracknell.net/955/warning-mysqli_query-function-mysqli-query-couldnt-fetch-mysqli-in/</link>
		<comments>http://paulcracknell.net/955/warning-mysqli_query-function-mysqli-query-couldnt-fetch-mysqli-in/#comments</comments>
		<pubDate>Sat, 25 Aug 2012 11:52:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP MySQL Tips]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.paulcracknell.net/?p=955</guid>
		<description><![CDATA[This warning is confusing and can cause heaps of wasted time.  I have found that the line where the warning says the problem is, is not really the problem. Remove extra mysql_close statements and this will probably fix it.]]></description>
				<content:encoded><![CDATA[<p>This warning is confusing and can cause heaps of wasted time.  I have found that the line where the warning says the problem is, is not really the problem.</p>
<p>Remove extra mysql_close statements and this will probably fix it.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulcracknell.net/955/warning-mysqli_query-function-mysqli-query-couldnt-fetch-mysqli-in/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to take your WordPress website and replicate it on wamp</title>
		<link>http://paulcracknell.net/911/how-to-take-your-wordpress-website-and-replicate-it-on-wamp/</link>
		<comments>http://paulcracknell.net/911/how-to-take-your-wordpress-website-and-replicate-it-on-wamp/#comments</comments>
		<pubDate>Sun, 24 Jun 2012 07:20:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP MySQL Tips]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.paulcracknell.net/?p=911</guid>
		<description><![CDATA[I had a situation recently where I had a fully operational website running on the web and I needed / wanted to make some radical changes to the theme and I wanted to interact with the current database. I use wamp for a local test server and wanted to replicate the entire website to my [...]]]></description>
				<content:encoded><![CDATA[<p>I had a situation recently where I had a fully operational website running on the web and I needed / wanted to make some radical changes to the theme and I wanted to interact with the current database. I use wamp for a local test server and wanted to replicate the entire website to my local machine. It took a little stuffing around so I have made a short list to help others out wanting to do the same or in case I forget and need to remember how.</p>
<h1>Step One</h1>
<p>Get the latest version of WordPress from wordpress.org<br />
Unzip the package and add it to the www directory in wamp.</p>
<h1>Step Two</h1>
<p>Run the activation of WordPress from scratch to make the database and config.php page. Check http://localhost/yoursite/</p>
<h1>Step Three</h1>
<p>Assuming it is all working locally we can now start to make the conversion. Copy the entire wp-content directory from your working site into your local site files (e.g Delete the local wp-content and replace it with the website version)</p>
<h1>Step Four</h1>
<p>Open up phpMyAdmin for your live site. Your hosting provider should give you access to this through cpanel or something similar. Open the database that relates to your live site and then click on the Export tab at the top of the page. The default settings are usually fine. Just make sure that you are exporting and sql file. Save it to your desktop where you can easily locate it later. This may take a while depending on the amount of data you have stored.</p>
<h1>Step Five</h1>
<p>Open phpMyAdmin for your local wamp server. The green W in system tools will allow you to do this quickly. Open the new database that you just created in Step Two. Click on the Structure tab at the top of the page and all the tables within your database will then be displayed. Select all the tables withthe select all link at the bottom or click on each checkbox. Use the drop down menu at the bottom of the tables and select drop. This will delete all the tables that you have in your database on the local server. NOTE: Ensure you are dropping the localhost tables not your live site ones.</p>
<h1>Step Six</h1>
<p>When your live database download has finished check the size of the file. If it is over 2 megabytes you will have to zip the file in order to allow phpMyAdmin to upload the data. Zip it with you favourite zipping program. If it is still over 2 mb after zipping you will have to make changes to the post_max_size = 8M<br />
upload_max_filesize = 2M<br />
in the php.ini file within wamp. Just ensure that the post_max_size is larger or the same as the upload_max_filesize.</p>
<h1>Step Seven</h1>
<p>In your local phpMyAdmin while still in the database that you created and have just deleted the files from import the new database information. Click on the import tab and select the sql file or zip file and click on go.</p>
<h1>Step Eight</h1>
<p>If all went well you will have a whole new set of tables in your new database. In order to be able to access the localhost now click on the wp-options table. The fist entry in the table should be siteurl under the heading of option name. Click on the pencil to edit this. Change the http://yoursite.com to http://localhost/yoursite.</p>
<h1>Step Nine</h1>
<p>Go to http:/localhost/yoursite/wp-admin/ and log in the same as you would in your live site. When you reach the dashboard check the address bar of the browser to ensure you are in the right site. Go to Settings&gt;General in the dashboard area. Change &#8216;site address url&#8217; to the same as &#8216;WordPress Address URL&#8217; e.g. http:/localhost/yoursite.</p>
<h1>Step Ten</h1>
<p>Check the front end to see if everything is working ok. If you have changed how your permalinks work you may not be able to view pages or posts etc. Go to Settings&gt;Permalinks and select &#8216;default&#8217; which should rectify any problems.</p>
<p>That is it hope it helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulcracknell.net/911/how-to-take-your-wordpress-website-and-replicate-it-on-wamp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
