<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.2" -->
<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/"
	>

<channel>
	<title>PHP-ist: All about learning PHP, frameworks, tips and tricks</title>
	<link>http://php.fallenray.com</link>
	<description>PHP4, PHP5, cakephp, codeigniter, code example (scriptlets / snipplets) and many easy and effective way to learn</description>
	<pubDate>Thu, 06 Mar 2008 07:12:01 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.2</generator>
	<language>en</language>
			<item>
		<title>PHP5: Screen scraping with DOM and XPath</title>
		<link>http://php.fallenray.com/php5/php5-screen-scraping-with-dom-and-xpath/</link>
		<comments>http://php.fallenray.com/php5/php5-screen-scraping-with-dom-and-xpath/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 07:09:00 +0000</pubDate>
		<dc:creator>PHP-ist</dc:creator>
		
		<category><![CDATA[php5]]></category>

		<guid isPermaLink="false">http://php.fallenray.com/php5/php5-screen-scraping-with-dom-and-xpath/</guid>
		<description><![CDATA[This tutorial is continuation from previous yahoo screen-scraping using PHP4 tutorial.
We will try different method using DOM and XPath which only supported in PHP5.
First, a bit knowledge of XPath is required. More about XPATH can be read on:
http://www.zvon.org/xxl/XPathTutorial/General/examples.html
Also there's small concern that using XPATH is a bit slower than pure DOM Traversal. Read Speed: DOM [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial is continuation from previous <a href="/php4/php4-how-to-steal-from-yahoo-another-web-screen-scraper/">yahoo screen-scraping using PHP4 tutorial</a>.<br />
We will try different method using DOM and XPath which only supported in PHP5.</p>
<p>First, a bit knowledge of XPath is required. More about XPATH can be read on:<br />
http://www.zvon.org/xxl/XPathTutorial/General/examples.html</p>
<p>Also there's small concern that using XPATH is a bit slower than pure DOM Traversal. Read <a rel="external nofollow" href="http://www.sklar.com/blog/archives/85-Speed-DOM-traversal-vs.-XPath-in-PHP-5.html">Speed: DOM traversal vs. XPath in PHP 5</a><br />
But i personally also think that XPath is neat and easier.</p>
<p>Let's start. First we diagnose document structure using Mozilla Firebug.<br />
Try a very easy case, which is to grab the title "Top Movies":<br />
<img src="http://php.fallenray.com/wp-content/uploads/2008/03/xpath-example-1.png" alt="" border="0"><br />
Copy XPath using Firebug and get this query:</p>
<blockquote><p>
/html/body/center/table[8]/tbody/tr/td[5]/table[4]/tbody/tr/td/font/b
</p></blockquote>
<ol>
<li>Firefox automatically fix broken html structure, and it also add <b>tbody</b> tag. So, we need to remove this tag.</li>
<li>Only grab <b>first row</b> of table. Change .../<b>tr</b>/td/font/b into .../<b>tr[1]</b>/td/font/b</li>
</ol>
<p>Now we get our first XPath query:</p>
<blockquote><p>
/html/body/center/table[8]/tr/td[5]/table[4]/tr[1]/td/font
</p></blockquote>
<p>Next harder case is to grab contents.<br />
<img src="http://php.fallenray.com/wp-content/uploads/2008/03/xpath-example-2.png" alt="" border="0"><br />
XPath query from Firebug is:</p>
<blockquote><p>
/html/body/center/table[8]/tbody/tr/td[5]/table[4]/tbody/tr[2]/td[2]/a/font/b
</p></blockquote>
<ol>
<li>Same problem here. Firefox automatically fix broken html structure, and it also add <b>tbody</b> tag. Remove <b>tbody</b> tag from XPath query.</li>
<li>Grab <b>all row</b> of table. Change .../<b>tr[2]</b>/td[2]/a/font/b into .../<b>tr</b>/td[2]/a/font/b</li>
</ol>
<p>Final XPath query for content is:</p>
<blockquote><p>
/html/body/center/table[8]/tr/td[5]/table[4]/tr/td[2]/a/font/b
</p></blockquote>
<p>Now final step is to put all two XPath queries into few lines of code, and we're done:</p>
<div class="igBar"><span id="lphp-2"><a href="#" onclick="javascript:showPlainTxt('php-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-2">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/error_reporting"><span style="color:#000066;">error_reporting</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">E_ERROR</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<span style="color:#FF9933; font-style:italic;">// | E_WARNING | E_PARSE);</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">include</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Snoopy.class.php'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$snooper</span> = <span style="color:#000000; font-weight:bold;">new</span> Snoopy<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$snooper</span>-&gt;<span style="color:#006600;">fetch</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'http://movies.yahoo.com/mv/boxoffice/'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$dom</span> = <span style="color:#000000; font-weight:bold;">new</span> DomDocument<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$dom</span>-&gt;<span style="color:#006600;">loadHTML</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$snooper</span>-&gt;<span style="color:#006600;">results</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$x</span> = <span style="color:#000000; font-weight:bold;">new</span> DomXPath<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$dom</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//&nbsp; /html/body/center/table[8]/tbody/tr/td[5]/table[4]/tbody/tr/td/font/b</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$nodes</span> = <span style="color:#0000FF;">$x</span>-&gt;<span style="color:#006600;">query</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'/html/body/center/table[8]/tr/td[5]/table[4]/tr[1]/td/font/b'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$nodes</span>-&gt;<span style="color:#006600;">item</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">nodeValue</span>, <span style="color:#FF0000;">"&lt;br/&gt;<span style="color:#000099; font-weight:bold;">\n</span>"</span>; <span style="color:#FF9933; font-style:italic;">//Top Movies</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//&nbsp; /html/body/center/table[8]/tbody/tr/td[5]/table[4]/tbody/tr[2]/td[2]/a/font/b</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$nodes</span> = <span style="color:#0000FF;">$x</span>-&gt;<span style="color:#006600;">query</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'/html/body/center/table[8]/tr/td[5]/table[4]/tr/td[2]/a/font/b'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">foreach</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$nodes</span> <span style="color:#616100;">as</span> <span style="color:#0000FF;">$node</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$node</span>-&gt;<span style="color:#006600;">nodeValue</span>, <span style="color:#FF0000;">"&lt;br/&gt;<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><!-- technorati tags begin --></p>
<p style="font-size: 10px; text-align: right;">Tags: <a href="http://technorati.com/tag/php5" rel="tag nofollow">php5</a>, <a href="http://technorati.com/tag/cakephp" rel="tag nofollow">screen scraping</a>, <a href="http://technorati.com/tag/code+example" rel="tag nofollow">code example</a></p>
<p><!-- technorati tags end --></p>
]]></content:encoded>
			<wfw:commentRss>http://php.fallenray.com/php5/php5-screen-scraping-with-dom-and-xpath/feed/</wfw:commentRss>
		</item>
		<item>
		<title>CakePHP: How to add Search Engine Friendly (SEF) URLs</title>
		<link>http://php.fallenray.com/cakephp/cakephp-how-to-add-search-engine-friendly-sef-urls/</link>
		<comments>http://php.fallenray.com/cakephp/cakephp-how-to-add-search-engine-friendly-sef-urls/#comments</comments>
		<pubDate>Mon, 18 Feb 2008 13:43:08 +0000</pubDate>
		<dc:creator>PHP-ist</dc:creator>
		
		<category><![CDATA[cakephp]]></category>

		<guid isPermaLink="false">http://php.fallenray.com/cakephp/cakephp-how-to-add-search-engine-friendly-sef-urls/</guid>
		<description><![CDATA[How many times you wondered how great it would be if your URLs didn't look so much like:
···http://www.server.com/posts/view/1058
But more like:
···http://www.server.com/posts/view/my_first_post
Read the rest on:
http://bakery.cakephp.org/articles/view/adding-friendly-urls-to-the-cake-blog-tutorial
]]></description>
			<content:encoded><![CDATA[<p>How many times you wondered how great it would be if your URLs didn't look so much like:<br />
···http://www.server.com/posts/view/1058<br />
But more like:<br />
···http://www.server.com/posts/view/my_first_post</p>
<p>Read the rest on:<br />
http://bakery.cakephp.org/articles/view/adding-friendly-urls-to-the-cake-blog-tutorial</p>
]]></content:encoded>
			<wfw:commentRss>http://php.fallenray.com/cakephp/cakephp-how-to-add-search-engine-friendly-sef-urls/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP4: How to Steal from Yahoo! (another Web Screen Scraper)</title>
		<link>http://php.fallenray.com/php4/php4-how-to-steal-from-yahoo-another-web-screen-scraper/</link>
		<comments>http://php.fallenray.com/php4/php4-how-to-steal-from-yahoo-another-web-screen-scraper/#comments</comments>
		<pubDate>Mon, 11 Feb 2008 06:57:55 +0000</pubDate>
		<dc:creator>PHP-ist</dc:creator>
		
		<category><![CDATA[php4]]></category>

		<guid isPermaLink="false">http://php.fallenray.com/php4/php4-how-to-steal-from-yahoo-another-web-screen-scraper/</guid>
		<description><![CDATA[If you've been wondering on how to scrape some information from your favorite website. This web screen scraping techniques has already there since dinosaur age. Here's an example on how to do it in PHP 4. Thanks to:

Mozilla Firefox and Firebug for spying and taking overall bird view so we could design a strategy.
The good [...]]]></description>
			<content:encoded><![CDATA[<p>If you've been wondering on how to scrape some information from your favorite website. This <b>web screen scraping techniques</b> has already there since dinosaur age. Here's an example on how to do it in PHP 4. Thanks to:</p>
<ol>
<li>Mozilla Firefox and Firebug for spying and taking overall bird view so we could design a strategy.</li>
<li>The good old snoopy-php project which will do his works as http client, snipping and sucking the whole page.</li>
<li>And also phphtmlparser that make dirty HTML parsing work a lot more easy, taking down the enemy element by element.</li>
</ol>
<p>First, our target operation is to grab a list of currently hot box office movies from Yahoo! Movies.<br />
Target located: http://movies.yahoo.com/mv/boxoffice/ ..... locked on!!!</p>
<p>We need to see the HTML layout of the page, using Firefox and Firebug<br />
<img src="http://php.fallenray.com/wp-content/uploads/2008/02/getting-html-layout-for-screen-scraping-yahoo-movies.png" alt="getting html layout for screen scraping yahoo movies" border="0"></p>
<p>Place your sight on the right side of screenshot.<br />
The area we want to steal started with <b>Top Movies</b> and ended with <b>Top Cast/Crew'</b>.<br />
Here's part of the code you'll see later.</p>
<div class="igBar"><span id="lphp-5"><a href="#" onclick="javascript:showPlainTxt('php-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-5">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">...</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incIf<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$step1</span>, <span style="color:#CC66CC;color:#800000;">0</span>, <span style="color:#0000FF;">$parser</span>-&gt;<span style="color:#006600;">iNodeValue</span> == <span style="color:#FF0000;">'Top Movies'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">...</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incIf<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$step1</span>, <span style="color:#CC66CC;color:#800000;">1</span>, <span style="color:#0000FF;">$parser</span>-&gt;<span style="color:#006600;">iNodeValue</span> == <span style="color:#FF0000;">'Top Cast/Crew'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">... </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now look at the bottom part. The full element tree starting from the root <b>html</b> tag, and ended in <b>b</b> tag.<br />
<img src="http://php.fallenray.com/wp-content/uploads/2008/02/xpath-for-screen-scraping-yahoo-movies.png" alt="xpath for screen firefox and firebug scraping yahoo movies" border="0"><br />
Decide that <b>b < font < a < td</b> should enough to distinct and separate the element from others.<br />
So we will use a variable $step2 for digging. If $step2 == 0 and current element is <b>td</b>, we set $step2 into 1. If $step2 == 1 and current element is <b>b</b>, increment it. This $step2 continues to dig further to <b>font</b> and until we reach the treasure box in <b>b</b> tag. Finally, print out what inside treasure box and go up again to the surface, set $step2 to 0.</p>
<p>Now it's time for the full code guys.<br />
If you're too lazy to copy paste it, just download the <a href="http://php.fallenray.com/wp-content/uploads/2008/02/stealyahoo.zip" target="_blank">source code of web scraping tutorial (PHP 4).</a></p>
<div class="igBar"><span id="lphp-6"><a href="#" onclick="javascript:showPlainTxt('php-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-6">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// Let's hire both experts</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">include</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Snoopy.class.php'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">include</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'htmlparser.inc'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// Move and dig deeper</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#000000; font-weight:bold;">function</span> incIf<span style="color:#006600; font-weight:bold;">&#40;</span>&amp;<span style="color:#0000FF;">$step_counter</span>, <span style="color:#0000FF;">$current_step</span>, <span style="color:#0000FF;">$condition</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$step_counter</span> == <span style="color:#0000FF;">$current_step</span><span style="color:#006600; font-weight:bold;">&#41;</span> &amp;&amp; <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$condition</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$step_counter</span> = <span style="color:#0000FF;">$current_step</span>+<span style="color:#CC66CC;color:#800000;">1</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// If it's deep enough, take it and leave;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#000000; font-weight:bold;">function</span> doIf<span style="color:#006600; font-weight:bold;">&#40;</span>&amp;<span style="color:#0000FF;">$step_counter</span>, <span style="color:#0000FF;">$current_step</span>, <span style="color:#0000FF;">$condition</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$step_counter</span> == <span style="color:#0000FF;">$current_step</span><span style="color:#006600; font-weight:bold;">&#41;</span> &amp;&amp; <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$condition</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$step_counter</span> = <span style="color:#CC66CC;color:#800000;">0</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">true</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">false</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// C'mon snoopy suck that page</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$snooper</span> = <span style="color:#000000; font-weight:bold;">new</span> Snoopy<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$snooper</span>-&gt;<span style="color:#006600;">fetch</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'http://movies.yahoo.com/mv/boxoffice/'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// Pass the page to HtmlParser, and let him do his work</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$parser</span> = <span style="color:#000000; font-weight:bold;">new</span> HtmlParser <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$snooper</span>-&gt;<span style="color:#006600;">results</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$step1</span> = <span style="color:#CC66CC;color:#800000;">0</span>; <span style="color:#0000FF;">$step2</span> = <span style="color:#CC66CC;color:#800000;">0</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"TODAY's BOX OFFICE<span style="color:#000099; font-weight:bold;">\r</span><span style="color:#000099; font-weight:bold;">\n</span>&lt;br/&gt;"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">while</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$parser</span>-&gt;<span style="color:#006600;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incIf<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$step1</span>, <span style="color:#CC66CC;color:#800000;">0</span>, <span style="color:#0000FF;">$parser</span>-&gt;<span style="color:#006600;">iNodeValue</span> == <span style="color:#FF0000;">'Top Movies'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incIf<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$step1</span>, <span style="color:#CC66CC;color:#800000;">1</span>, <span style="color:#0000FF;">$parser</span>-&gt;<span style="color:#006600;">iNodeValue</span> == <span style="color:#FF0000;">'Top Cast/Crew'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$step1</span> == <span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incIf<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$step2</span>, <span style="color:#CC66CC;color:#800000;">0</span>, <span style="color:#0000FF;">$parser</span>-&gt;<span style="color:#006600;">iNodeName</span> == <span style="color:#FF0000;">'TD'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incIf<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$step2</span>, <span style="color:#CC66CC;color:#800000;">1</span>, <span style="color:#0000FF;">$parser</span>-&gt;<span style="color:#006600;">iNodeName</span> == <span style="color:#FF0000;">'A'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incIf<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$step2</span>, <span style="color:#CC66CC;color:#800000;">2</span>, <span style="color:#0000FF;">$parser</span>-&gt;<span style="color:#006600;">iNodeName</span> == <span style="color:#FF0000;">'FONT'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incIf<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$step2</span>, <span style="color:#CC66CC;color:#800000;">3</span>, <span style="color:#0000FF;">$parser</span>-&gt;<span style="color:#006600;">iNodeName</span> == <span style="color:#FF0000;">'B'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>doIf<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$step2</span>, <span style="color:#CC66CC;color:#800000;">4</span>, <span style="color:#0000FF;">$parser</span>-&gt;<span style="color:#006600;">iNodeType</span> == NODE_TYPE_TEXT<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$parser</span>-&gt;<span style="color:#006600;">iNodeValue</span>.<span style="color:#FF0000;">"<span style="color:#000099; font-weight:bold;">\r</span><span style="color:#000099; font-weight:bold;">\n</span>&lt;br/&gt;"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><!-- technorati tags begin --></p>
<p style="font-size: 10px; text-align: right;">Tags: <a href="http://technorati.com/tag/php4" rel="tag nofollow">php4</a>, <a href="http://technorati.com/tag/cakephp" rel="tag nofollow">screen scraping</a>, <a href="http://technorati.com/tag/code+example" rel="tag nofollow">code example</a></p>
<p><!-- technorati tags end --></p>
]]></content:encoded>
			<wfw:commentRss>http://php.fallenray.com/php4/php4-how-to-steal-from-yahoo-another-web-screen-scraper/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Cake PHP: Simple Contact Form Tutorial!</title>
		<link>http://php.fallenray.com/cakephp/cake-php-simple-contact-form-tutorial/</link>
		<comments>http://php.fallenray.com/cakephp/cake-php-simple-contact-form-tutorial/#comments</comments>
		<pubDate>Fri, 08 Feb 2008 14:11:28 +0000</pubDate>
		<dc:creator>PHP-ist</dc:creator>
		
		<category><![CDATA[cakephp]]></category>

		<guid isPermaLink="false">http://php.fallenray.com/cakephp/cake-php-simple-contact-form-tutorial/</guid>
		<description><![CDATA[