<?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>Freelance Web Development Resource</title>
	<atom:link href="http://www.dolrichfortich.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dolrichfortich.com/blog</link>
	<description>web development resources - dolrich fortich</description>
	<lastBuildDate>Thu, 24 Nov 2011 07:22:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Simple curl sample codes</title>
		<link>http://www.dolrichfortich.com/blog/php/simple-curl-sample-codes/</link>
		<comments>http://www.dolrichfortich.com/blog/php/simple-curl-sample-codes/#comments</comments>
		<pubDate>Mon, 17 Oct 2011 05:26:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.dolrichfortich.com/blog/?p=54</guid>
		<description><![CDATA[Here are some simple curl codes I commonly use. #1 &#8211; Fetch url content (basic GET request) #2 &#8211; Fetch url content (basic POST request) #3 &#8211; Curl request with session #Tips in case the code above is not working 1. The site probably restricts request not sent by common browsers. To imitate a browser, [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some simple curl codes I commonly use.</p>
<p><strong>#1 &#8211; Fetch url content (basic GET request)</strong></p>
<pre class="brush: php; title: ; notranslate">
$curl_url = 'http://www.example.com/sample.php';

$ch=curl_init($curl_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_result = curl_exec($ch);
curl_close($ch);
</pre>
<p><strong>#2 &#8211; Fetch url content (basic POST request)</strong></p>
<pre class="brush: php; title: ; notranslate">
$curl_post_data = array(
	'variable_1' =&gt; 'data_1',
	'variable_2' =&gt; 'data_2'
	);
$curl_url = 'http://www.example.com/sample.php';

$ch = curl_init ($curl_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($curl_post_data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_result = curl_exec ($ch);
curl_close ($ch);

echo $curl_result;
</pre>
<p><strong>#3 &#8211; Curl request with session</strong></p>
<pre class="brush: php; title: ; notranslate">
</pre>
<p><strong>#Tips in case the code above is not working<br />
</strong></p>
<p>1. The site probably restricts request not sent by common browsers. To imitate a browser, add the curl option below.</p>
<pre class="brush: php; title: ; notranslate">
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
				'Host: example.com',
				'User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20100101 Firefox/8.0',
				'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
				'Accept-Language: en-us,en;q=0.5',
				'Connection: keep-alive',
				));
</pre>
<p>2. Youre probably accessing an https site.</p>
<pre class="brush: php; title: ; notranslate">&lt;code&gt;
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);&lt;/code&gt;
</pre>
<p>More info regarding this,</p>
<p>http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/</p>
<p>3. Check if there is an error</p>
<p>Place this before closing the curl connection.</p>
<pre class="brush: php; title: ; notranslate">
$curl_error = curl_error($ch);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dolrichfortich.com/blog/php/simple-curl-sample-codes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Count numbers in a string</title>
		<link>http://www.dolrichfortich.com/blog/php/count-numbers-in-a-string/</link>
		<comments>http://www.dolrichfortich.com/blog/php/count-numbers-in-a-string/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 03:30:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.dolrichfortich.com/blog/?p=50</guid>
		<description><![CDATA[Function to count numbers in a string. Ex: (123) 456-7891 Numbers in a string: 10]]></description>
			<content:encoded><![CDATA[<p>Function to count numbers in a string.<br />
Ex: (123) 456-7891<br />
Numbers in a string: 10</p>
<pre class="brush: php; title: ; notranslate">
function count_numbers($string)
{
  preg_match_all('/[0-9]/', $string, $matches);
  return count($matches[0]);
}

$string = '(123) 456-7891';
echo count_numbers($string);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dolrichfortich.com/blog/php/count-numbers-in-a-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Determining the delimeter used in a CSV file</title>
		<link>http://www.dolrichfortich.com/blog/php/determining-delimeter-used-csv-file/</link>
		<comments>http://www.dolrichfortich.com/blog/php/determining-delimeter-used-csv-file/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 11:56:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.dolrichfortich.com/blog/?p=40</guid>
		<description><![CDATA[Just today, I was tasked to create an application for a client to process google adwords reports from a csv file. Everything went well till more csv files were uploaded, some of the csv files were not really comma(,) separated. The function below did solve the problem. You can see here part of the code [...]]]></description>
			<content:encoded><![CDATA[<p>Just today, I was tasked to create an application for a client to process<br />
google adwords reports from a csv file.</p>
<p>Everything went well till more csv files were uploaded, some of the csv files were not really<br />
comma(,) separated. The function below did solve the problem.</p>
<pre class="brush: php; title: ; notranslate">
function get_csv_delimeter($csv_text)
{
	$delimeters = array(',',';','|','~',&quot;\t&quot;);
	$current_delimeter_count = 0;
	$current_delimeter = FALSE;

	foreach($delimeters as $delimeter)
	{
		if(substr_count($csv_text, $delimeter) &gt; $current_delimeter_count)
		{
			$current_delimeter = $delimeter;
		}
	}

	return $current_delimeter;
}
</pre>
<p>You can see here part of the code that process the csv file. What it does is<br />
to place the data into an array.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$csv_data = array();

if(isset($_FILES['csv']) AND
	$_FILES['csv']['type'] == 'text/csv' AND
	! $_FILES['csv']['error'])
{
	$row = 1;
	if (($handle = fopen($_FILES['csv']['tmp_name'], &quot;r&quot;)) !== FALSE) {

		//Reading the first line from the file
		if(($data = fgets($handle)) !== FALSE) {

			//The function used to detect determine the delimeter
			$delimeter = get_csv_delimeter($data);

			//Reset the file pointer to the beginning
			rewind($handle);
		}

		while (($data = fgetcsv($handle, 1000, $delimeter)) !== FALSE) {

			for ($c=0; $c &lt; $num; $c++) {
				$csv_data[$row][$c] = utf8_encode(preg_replace('/[^(\x20-\x7F)\x0A]*/','', $data[$c]));
			}
			$row++;
		}

		fclose($handle);
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dolrichfortich.com/blog/php/determining-delimeter-used-csv-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grouping of WHERE statement using CodeIniter Active Record</title>
		<link>http://www.dolrichfortich.com/blog/codeigniter/grouping-of-where-statement-using-codeiniter-active-record/</link>
		<comments>http://www.dolrichfortich.com/blog/codeigniter/grouping-of-where-statement-using-codeiniter-active-record/#comments</comments>
		<pubDate>Thu, 26 May 2011 15:22:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>

		<guid isPermaLink="false">http://www.dolrichfortich.com/blog/?p=26</guid>
		<description><![CDATA[To generate this SQL query using CodeIgniter Active Record. You can do it like this. Let me know if you have a better way to do this.]]></description>
			<content:encoded><![CDATA[<p>To generate this SQL query using CodeIgniter Active Record.</p>
<pre class="brush: sql; title: ; notranslate">
SELECT `id` FROM (`users`)
		WHERE
			(first_name = 'test1' AND age =18) OR
			(last_name = 'test2' AND age =17)
</pre>
<p>You can do it like this.</p>
<pre class="brush: php; title: ; notranslate">
$first_name = 'test1';
$last_name = 'test2';
$age1 = 18;
$age2 = 17;

$this-&gt;db-&gt;select('id')
  -&gt;from('users')

  -&gt;where('(first_name', $first_name)
  -&gt;where('age', $this-&gt;db-&gt;escape($age1).')', FALSE)

  -&gt;or_where('(last_name', $last_name)
  -&gt;where('age', $this-&gt;db-&gt;escape($age2).')', FALSE)

  -&gt;get();
</pre>
<p>Let me know if you have a better way to do this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dolrichfortich.com/blog/codeigniter/grouping-of-where-statement-using-codeiniter-active-record/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculating age in javascript</title>
		<link>http://www.dolrichfortich.com/blog/javascript/calculating-age-in-javascript/</link>
		<comments>http://www.dolrichfortich.com/blog/javascript/calculating-age-in-javascript/#comments</comments>
		<pubDate>Wed, 25 May 2011 04:00:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.dolrichfortich.com/blog/?p=7</guid>
		<description><![CDATA[Here is method in calculating age in javascript. Its pretty simple, based from a sample age calculation code written in php which you can find here http://www.bradino.com/php/calculate-age/ Sample usage.]]></description>
			<content:encoded><![CDATA[<p>Here is method in calculating age in javascript. Its pretty simple, based from a sample age calculation code written in php which you can find here <a href="http://www.bradino.com/php/calculate-age/">http://www.bradino.com/php/calculate-age/</a></p>
<pre class="brush: jscript; title: ; notranslate">
function calculate_age(yr, mon, day)
{
 var d=new Date(Date.UTC(yr,mon-1,day,0,0,0)).getTime();
 var d1=new Date().getTime();
 return Math.floor((Math.round(d1 / 1000) - Math.round(d / 1000))/31556926);
}
</pre>
<p>Sample usage.</p>
<pre class="brush: jscript; title: ; notranslate">
document.write(calculate_age(1956, 5, 24));
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dolrichfortich.com/blog/javascript/calculating-age-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

