<?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>adc&#124;works &#187; PHP</title>
	<atom:link href="http://www.adcworks.com/category/development/web/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.adcworks.com</link>
	<description></description>
	<lastBuildDate>Wed, 06 Jan 2010 15:47:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Checking if a UK date is in the past with PHP</title>
		<link>http://www.adcworks.com/2010/01/checking-if-a-uk-date-is-in-the-past-with-php/</link>
		<comments>http://www.adcworks.com/2010/01/checking-if-a-uk-date-is-in-the-past-with-php/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 15:21:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.adcworks.com/?p=57</guid>
		<description><![CDATA[The easiest way to check if a date is in the past with PHP is using strtotime but unfortunately it only understands US and Unix date formats, not the UK&#8217;s format d/m/Y. A UK date string therefore needs to be transformed first. You will need to use a regular expression to first validate that your]]></description>
			<content:encoded><![CDATA[<p>The easiest way to check if a date is in the past with PHP is using strtotime but unfortunately it only understands US and Unix date formats, not the UK&#8217;s format d/m/Y.</p>
<p>A UK date string therefore needs to be transformed first. You will need to use a regular expression to first <a href="http://www.google.com/search?hl=en&amp;q=uk+date+format+regex&amp;btnG=Search&amp;meta=&amp;aq=f&amp;oq=" target="_blank">validate that your UK date is valid.</a> I do not set this out here. Once you are sure you have a UK valid date string of the format d/m/Y, e.g. 01/02/2010 you can do the following:</p>
<pre class="brush: php">
// tests a uk date string for being in the past. time components will be midnight for test to work.
function is_uk_date_in_past($pre_validated_uk_date_string_no_time) {
    list($d, $m, $y) = explode(&#039;/&#039;, $pre_validated_uk_date_string_no_time);
    $today = strtotime(date(&quot;Y-m-d&quot;)); // we do not define today as time() as that will include the current time
    $given = strtotime(&quot;{$y}-{$m}-{$d}&quot;);
    return $given &gt;= $today;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.adcworks.com/2010/01/checking-if-a-uk-date-is-in-the-past-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Igniter Date Validation</title>
		<link>http://www.adcworks.com/2009/04/code-igniter-date-validation/</link>
		<comments>http://www.adcworks.com/2009/04/code-igniter-date-validation/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 13:39:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Igniter]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.adcworks.com/?p=38</guid>
		<description><![CDATA[Those looking for a Code Igniter date validator rule can use the following custom validation. This is written for CI 1.7+ To use, copy the class below into your system/application/libraries folder named MY_Form_validation.php, then in your controller use it like any other rule. Oh, and this is the first version so if you do come]]></description>
			<content:encoded><![CDATA[<p>Those looking for a Code Igniter date validator rule can use the following custom validation. This is written for CI 1.7+</p>
<p>To use, copy the class below into your system/application/libraries folder named MY_Form_validation.php, then in your controller use it like any other rule.</p>
<p>Oh, and this is the first version so if you do come across bugs/requests let me know would you? <img src='http://www.adcworks.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Cheers.</p>
<h3>Form</h3>
<p>This validation rule validates an input text box only right now.</p>
<pre class="brush: php">
&lt;input type=&quot;text&quot; name=&quot;date&quot; value=&quot;&lt;?php echo set_value(&#039;date&#039;); ?&gt;&quot; size=&quot;10&quot; /&gt;
</pre>
<h3>Controller Usage</h3>
<p>UK</p>
<pre class="brush: php">
$this-&gt;form_validation-&gt;set_rules(&#039;date&#039;, &#039;date&#039;, &#039;trim|required|valid_date[d/m/y,/]&#039;);
</pre>
<p>US</p>
<pre class="brush: php">
$this-&gt;form_validation-&gt;set_rules(&#039;date&#039;, &#039;date&#039;, &#039;trim|required|valid_date[m/d/y,/]&#039;);
</pre>
<p>Database</p>
<pre class="brush: php">
$this-&gt;form_validation-&gt;set_rules(&#039;date&#039;, &#039;date&#039;, &#039;trim|required|valid_date[y-m-d,-]&#039;);
</pre>
<h3>The Code</h3>
<pre class="brush: php">
&lt;?php if (!defined(&#039;BASEPATH&#039;)) exit(&#039;No direct script access allowed&#039;);

class MY_Form_validation extends CI_Form_validation {

    function MY_Form_validation()
    {
        parent::CI_Form_validation();
    }

    /**
    * @desc Validates a date format
    * @params format,delimiter
    * e.g. d/m/y,/ or y-m-d,-
    */
    function valid_date($str, $params)
    {
        // setup
        $CI =&amp;amp;amp;amp;amp;amp; get_instance();
        $params = explode(&#039;,&#039;, $params);
        $delimiter = $params[1];
        $date_parts = explode($delimiter, $params[0]);

        // get the index (0, 1 or 2) for each part
        $di = $this-&gt;valid_date_part_index($date_parts, &#039;d&#039;);
        $mi = $this-&gt;valid_date_part_index($date_parts, &#039;m&#039;);
        $yi = $this-&gt;valid_date_part_index($date_parts, &#039;y&#039;);

        // regex setup
        $dre = &quot;(0?1|0?2|0?3|0?4|0?5|0?6|0?7|0?8|0?9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)&quot;;
        $mre = &quot;(0?1|0?2|0?3|0?4|0?5|0?6|0?7|0?8|0?9|10|11|12)&quot;;
        $yre = &quot;([0-9]{4})&quot;;
        $red = &#039;\\&#039;.$delimiter; // escape delimiter for regex
        $rex = &quot;^[0]{$red}[1]{$red}[2]$&quot;;

        // do replacements at correct positions
        $rex = str_replace(&quot;[{$di}]&quot;, $dre, $rex);
        $rex = str_replace(&quot;[{$mi}]&quot;, $mre, $rex);
        $rex = str_replace(&quot;[{$yi}]&quot;, $yre, $rex);

        if (ereg($rex, $str, $matches)) {
            // skip 0 as it contains full match, check the date is logically valid
            if (checkdate($matches[$mi + 1], $matches[$di + 1], $matches[$yi + 1])) {
                return true;
            } else {
                // match but logically invalid
                $CI-&gt;form_validation-&gt;set_message(&#039;valid_date&#039;, &quot;The date is invalid.&quot;);
                return false;
            }
        } 

        // no match
        $CI-&gt;form_validation-&gt;set_message(&#039;valid_date&#039;, &quot;The date format is invalid. Use {$params[0]}&quot;);
        return false;
    }      

    function valid_date_part_index($parts, $search) {
        for ($i = 0; $i &lt;= count($parts); $i++) {
            if ($parts[$i] == $search) {
                return $i;
            }
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.adcworks.com/2009/04/code-igniter-date-validation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PHP SoapClient Could Not Connect to Host</title>
		<link>http://www.adcworks.com/2008/04/php-soapclient-could-not-connect-to-host/</link>
		<comments>http://www.adcworks.com/2008/04/php-soapclient-could-not-connect-to-host/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 21:24:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://adcworks/?p=11</guid>
		<description><![CDATA[The Could Not Connect to Host error message when using PHP SoapClient can be a tricky sucker to trace the root of. There are varying responses across the internets to what may cause this problem such as firewalls and proxies. But there is one other thing you can check. Look through the WSDL for the]]></description>
			<content:encoded><![CDATA[<p>The Could Not Connect to Host error message when using PHP SoapClient can be a tricky sucker to trace the root of. There are varying responses across the internets to what may cause this problem such as firewalls and proxies.</p>
<p>But there is one other thing you can check. Look through the WSDL for the soap:address locations. You may find that a server name is given that the machine running your code does not have access to.</p>
<p>Take a look at the example below;</p>
<pre class="brush: xml">&lt;service name=&quot;SomeService&quot;&gt;
  &lt;port binding=&quot;tns:WebServiceBinding&quot; name=&quot;WebServicePort&quot;&gt;
    &lt;soap:address location=&quot;http://appserver3:8080/webservices/WebServiceEndPoint&quot;/&gt;
  &lt;/port&gt;
&lt;/service&gt;
</pre>
<p>I experienced the issue when deploying my code from my dev machine to a live server. I couldn&#8217;t understand why my dev machine was fine calling the web services and the live server was not.</p>
<p>That&#8217;s because I had forgotten that I had provided access to my dev machine in the early days of coding to the appserver3 server name by virtue of a hosts file entry. Looking in my hosts file revealed</p>
<p>123.123.123.123  appserver3</p>
<p>And this is what was missing on the live server.</p>
<p>So if you get this error and you just can&#8217;t figure it out, take a wander through the WSDL for location URLs that may not be accessible to the server running your code. If you have a server name rather than an IP as in the example above, then add a hosts file mapping to the IP and you&#8217;re away.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adcworks.com/2008/04/php-soapclient-could-not-connect-to-host/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
