<?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>Shawn Plep &#187; PHP</title>
	<atom:link href="http://shawnplep.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://shawnplep.com</link>
	<description>Shawn Plep is a web programmer, SEO, and hacker from New Orleans, Louisiana.</description>
	<lastBuildDate>Wed, 07 Jul 2010 18:22:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating Better CSV Files With Excel</title>
		<link>http://shawnplep.com/php/creating-better-csv-files-with-excel/</link>
		<comments>http://shawnplep.com/php/creating-better-csv-files-with-excel/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 22:19:43 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[datafeed]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[separator]]></category>

		<guid isPermaLink="false">http://shawnplep.com/?p=67</guid>
		<description><![CDATA[Excel is a great tool for a number of reasons. But when it&#8217;s used to create CSV files, it usually throws something at me that&#8217;s hard to parse.
I often need to use a script to parse CSVs (datafeeds, database exports, or just spreadsheets of data) and grab data, or reformat the CSV, but a problem [...]]]></description>
			<content:encoded><![CDATA[<p>Excel is a great tool for a number of reasons. But when it&#8217;s used to create CSV files, it usually throws something at me that&#8217;s hard to parse.</p>
<p>I often need to use a script to parse CSVs (datafeeds, database exports, or just spreadsheets of data) and grab data, or reformat the CSV, but a problem I&#8217;ve run into many times is the fact the Excel exports to CSV and does not allow me to enclose the fields in quotes, double-quotes, or&#8230;anything. And it separate the fields by commas. And that&#8217;s just how it is. (No options!)</p>
<p>So, instead of doing regex acrobatics or parsing contortions, there&#8217;s a way to make Excel export in a much easier-to-parse format.</p>
<p>To do this, you must change a Windows XP setting. Click Start-&gt;Settings-&gt;Control Panel-&gt;Regional and Language Options. Next to the Language, click &#8220;Customize&#8221;. Next, chnage the &#8220;List Separator&#8221; (under the Numbers tab) to something very unique. I use a tilde (&#8220;~&#8221;) symbol, due to the fact that I rarely find that within the data I&#8217;m working with. But you can use something else such as a pipe symbol.</p>
<p>Then, export your data to CSV. Your fields will have a more unique separator which you can easily distinguish. If you want, you can easily do a search-and-replace of that symbol as well. It&#8217;s saved me a lot of time!</p>
]]></content:encoded>
			<wfw:commentRss>http://shawnplep.com/php/creating-better-csv-files-with-excel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My 9 Best Coding Tips</title>
		<link>http://shawnplep.com/php/my-9-best-coding-tips/</link>
		<comments>http://shawnplep.com/php/my-9-best-coding-tips/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 12:16:11 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[programming tips]]></category>

		<guid isPermaLink="false">http://shawnplep.com/?p=30</guid>
		<description><![CDATA[Over the last few years, I&#8217;ve learned a lot about programming and coding sites. Some of this knowledge came from books, but the majority of the really good things I&#8217;ve learned came from simply &#8220;doing it&#8221; &#8211; trying things, experimenting, and just learning what works best and what doesn&#8217;t work. In other words, experience really [...]]]></description>
			<content:encoded><![CDATA[<p>Over the last few years, I&#8217;ve learned a lot about programming and coding sites. Some of this knowledge came from books, but the majority of the really good things I&#8217;ve learned came from simply &#8220;doing it&#8221; &#8211; trying things, experimenting, and just learning what works best and what doesn&#8217;t work. In other words, experience really is the best teacher.</p>
<p>So here are nine &#8220;tips&#8221; &#8211; short but helpful things that can make your life easier when you develop a web app, website, or script. I will list these in no particular order &#8211; hopefully at least on thing in this list will be of use.</p>
<p><strong>Create a wireframe, sitemap, or content matrix before you ever start coding.</strong> Unless you&#8217;re hacking something out really quick &#8211; plan your programs. Seriously. I see many people just sit down and start coding, but in my opinion they waste far more time doing things that way. It&#8217;s far better to plan out your program first, work out the flow of events and logic, and then start coding. And you don&#8217;t need to use Omnigraffle or any tools to do this: I map out database structures, navigations, and wireframes on yellow legal pads. So plan your projects in the way that works for you best &#8211; but do it.</p>
<p><strong>Use a good text editor or IDE</strong>. I personally prefer Crimson Editor. If you&#8217;re on a Mac, Textmate is supposed to be good. But I would not recommend trying to code in Dreamweaver as I&#8217;ve seen some people attempt. You really need to get into the code &#8211; and I recommend this for HTML, CSS, as well as scripting.</p>
<p><strong>Group all &#8220;like&#8221; files.</strong> Have a directory for images, one for CSS, etc. Don&#8217;t throw it all in your main directory and expect to keep things in order. Grouping files that belong together will make maintenance much simpler.</p>
<p><strong>Name all include files with a leading underscore.</strong> Someone wrote this on their blog (I don&#8217;t remember who) and it&#8217;s helped me keep things organized for some time. I often have a file such as &#8220;__header.php&#8221;, &#8220;__footer.php&#8221;, or &#8220;__nav.php&#8221; and I can always tell which files are includes for other &#8220;main&#8221; files or template files by merely glancing at them. Also, by using the underscore character to name them, they will appear at the top of my directory listing by default.</p>
<p><strong>Indent your code with tabs, instead of spaces.</strong> It keeps the structure of your code consistent, and it takes less characters to make one tab than to make four spaces. I know it might seem insignificant, but I like to make my files as small as possible.</p>
<p><strong>Use comments, &#8220;stubs&#8221; and pseudocode when developing &#8211; liberally.</strong> There&#8217;s no reason that you can&#8217;t delete/replace this stuff later if you don&#8217;t need it. But initially, I find it useful to &#8220;jump right in&#8221; and actually create the file(s) for my program and make myself notes where things are missing or where I haven&#8217;t yet implemented something.</p>
<p><strong>Don&#8217;t use inline styles.</strong> This is a general rule that I&#8217;ve found should rarely be broken. Learn how to control all your pages with a stylesheet. You&#8217;ll see the beauty and simplicity of it if you&#8217;ve ever had to hunt through multiple pages for stray inline styles when you needed to make a change.</p>
<p><strong>When you begin to get unproductive, go for a walk.</strong> I find that there are three activities where I can really think creatively and productively: mowing the lawn, taking a shower, and going for a walk. Seriously, many of my best ideas come to me in the shower! But taking a walk usually clears my head, as well. The essential ingredient here is the &#8220;zoning out&#8221; factor paired with no interruptions.</p>
<p><strong>If you can&#8217;t think of a way to solve a problem, present the situation to a non-programmer. </strong>This might sound like it&#8217;s the wrong way to approach a coding problem, but it works very well. (Of course, you have to strip the problem down to its essentials and present it in non-technical terms.) But if you have someone you can bounce problems off of and they have no pre-conceived ideas about how you&#8217;re &#8220;supposed to do it&#8221;, you might be surprised at the insights you&#8217;ll get from them.</p>
<p>There you have it: nine very specific ideas to help programmers. Whether you code in Perl, Ruby, or PHP or if you&#8217;re making small web sites or huge web applications one of these ideas is sure to crop up in the near future. I hope you find at least one of these tips helpful when that time comes!</p>
]]></content:encoded>
			<wfw:commentRss>http://shawnplep.com/php/my-9-best-coding-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automating Shareasale Affiliate Reporting w/ PHP &amp; cURL</title>
		<link>http://shawnplep.com/php/automating-shareasale-affiliate-reporting-w-php-curl/</link>
		<comments>http://shawnplep.com/php/automating-shareasale-affiliate-reporting-w-php-curl/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 21:34:16 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[shareasale]]></category>

		<guid isPermaLink="false">http://shawnplep.com/?p=7</guid>
		<description><![CDATA[For this example, I'm going to show you how to use PHP and cURL to check your Shareasale stats. I thought, "Why not prepare everyone with a nice way to automatically gather their stats?". But the following lesson can be applied to just about any affiliate site...or any website for that matter.]]></description>
			<content:encoded><![CDATA[<p>When you begin to get deep into the world of affiliate marketing, a few things happen:</p>
<p>   1. You begin to miss your family, because you&#8217;re always doing &#8220;computer stuff&#8221; they don&#8217;t understand<br />
   2. You have a lot of accounts at different merchants/affiliate networks and you log into those accounts all the time to check your income<br />
   3. You should be making some money</p>
<p>The number 3 part is what keeps people like you and I going. Otherwise we&#8217;d have better things to do with our time, right? Right. In fact &#8211; even while making money, we have better things to do with our time.</p>
<p>Hmmm&#8230;so what can we do about that? How can we maximize our time? I know: let&#8217;s do what I&#8217;m constantly harping about, and make a computer do the job we don&#8217;t need to do. In this case, let&#8217;s make a computer log into our affiliate accounts and check stats. Sound good? Good.</p>
<p>For this example, I&#8217;m going to show you how to use PHP and cURL to check your Shareasale stats. I thought, &#8220;Why not prepare everyone with a nice way to automatically gather their stats?&#8221;. But the following lesson can be applied to just about any affiliate site&#8230;or any website for that matter.</p>
<p>I assume you are familiar with running PHP scripts, at least. If you aren&#8217;t, there are some great books with animals on the cover to show you that. (And, perfectly good free websites to help you learn PHP, as well.)</p>
<p>So let&#8217;s just jump into it. Here&#8217;s a script that logs into Shareasale, grabs the current amount of income, and shows it to you.<br />
<code><br />
&lt;?php<br />
$username="superoptimist";<br />
$password="ibelieveinmyself";<br />
function return_between($string, $start, $stop, $type)<br />
    {<br />
    $temp = split_string($string, $start, AFTER, $type);<br />
    return split_string($temp, $stop, BEFORE, $type);<br />
    }<br />
$curl = curl_init();<br />
curl_setopt($curl, CURLOPT_REFERER, "http://www.shareasale.com/a-login.cfm");<br />
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");<br />
curl_setopt($curl, CURLOPT_COOKIEFILE, '/public_html/cookies/cookie.txt');<br />
curl_setopt($curl, CURLOPT_COOKIEJAR, '/public_html/cookies/cookie.txt');<br />
curl_setopt($curl, CURLOPT_POSTFIELDS, "step2=True&#038;username=$username&#038;password=$password&#038;submit.x=40&#038;submit.y=19");<br />
curl_setopt($curl, CURLOPT_POST, 1);<br />
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);<br />
curl_setopt($curl, CURLOPT_URL, "http://www.shareasale.com/a-login.cfm");<br />
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);<br />
$page = curl_exec($curl);<br />
echo "logged in";<br />
curl_setopt($curl, CURLOPT_GET, 1);<br />
curl_setopt($curl, CURLOPT_URL, "http://www.shareasale.com/a-main.cfm");<br />
curl_setopt($curl, CURLOPT_REFERER, "http://shareasale.com/a-login.cfm");<br />
$page = curl_exec($curl);<br />
$total=return_between($page, '&lt;font color=gold&gt; <B>$', '</B>', EXCL);<br />
echo 'got income amount';<br />
echo 'Total Amount $'.$total;<br />
curl_close($curl);<br />
?&gt;<br />
</code></p>
<p>And that&#8217;s it. Put your real SAS login info up in there, run it, and you will see a number appear on your screen &#8211; like $0.00, if you just opened your Shareasale account. But hopefully, eventually you&#8217;ll see some real income.</p>
<p>So why not just log in, manually? Well the point of me sharing this script is not to give you a marginally-useful script that you can use to get your current income. You can do so much more with this script once you think about the possibilities. Here are some:</p>
<p>    * Make an affiliate dashboard, and include all your affiliate reports in a nice, single menu with that day&#8217;s sales, that day&#8217;s hits, current income, etc.<br />
    * Grab all your affiliates&#8217; daily sales (running daily via cron) and throw that into a database. Use that to generate reports to show you things like: overall most profitable day of the week, most profitable merchant, product, etc. If you run a few scripts like this &#8211; say, one for SAS, one for CJ, one for CCBill, etc. and put it all together you can view reports like this across all your merchants and affiliate networks.<br />
    * Grab datafeeds daily or weekly from your merchants, and then update your databases (the ones that run your sites) with the latest products.</p>
<p>Get the idea? This is just an example of basic principles &#8211; but cURL is a powerful tool that can almost precisely behave like a web browser &#8211; just faster and automatically.</p>
<p>Hopefully you can follow the gist of what this script does, but here are a couple of pointers in case you need some cURL help.</p>
<p>Send what is expected. You must always send GET when the server expects a GET request, and a POST when POST is what&#8217;s expected. How to find that stuff out? LiveHTTPHeaders. Possibly the best FireFox plugin out there. At least to me. But there&#8217;s probably some weirdo out there with an Fellow Furry Finder plugin or something who thinks that&#8217;s the best. (Sorry, that&#8217;s not an actual plugin.)</p>
<p>Use LiveHTTPHeaders by selecting it, and then logging into the site you wish to write a cURL script for, and then examining the confusing stuff in the little window. All the stuff you will see is the conversation between your browser and the server. Your goal (in writing an automation script) is to replicate that conversation, or the format of that conversation.</p>
<p>Send in the order that is expected. This means that you must always have the proper referrer with each target URL. If every time a user who goes to accountadmin.php must have come from mainmenu.php, you better put mainmenu.php as your referrer when telling cURL to go to accountadmin.php. Follow the path that you would normally take (as a human, navigating a site).</p>
<p>Respect server resources. Do not do things like hammer a server every five seconds, or visit every hour and downloading a bunch of pics, or anything else like that. Remember Eli&#8217;s QUIT tool? Yeah, me too. I miss it. (*Sniff*). See, he shut down the thing just because of someone out there abusing the tool. If you do things like that to other people, they too will probably shut it down (at least, to your IP).</p>
<p>So did we learn something, kids? I hope so. I ain&#8217;t here to give ya&#8217;ll step-by-step instruction or nuthin&#8217; &#8211; but I wanted to at least whet your appetite for some of the things you can do with cURL and maybe give you some ideas. Any questions? I&#8217;ll do my best to answer.</p>
]]></content:encoded>
			<wfw:commentRss>http://shawnplep.com/php/automating-shareasale-affiliate-reporting-w-php-curl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
