<?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>Andrei DANEASA &#187; PHP</title>
	<atom:link href="http://www.webxpert.ro/andrei/category/programming/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webxpert.ro/andrei</link>
	<description>Programming, database, security, Oracle, .NET, C#, PHP, Travel</description>
	<lastBuildDate>Tue, 18 Oct 2011 15:42:40 +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>Book review: PHP 5 e-commerce Development by Michael Peacock (Packt Publishing)</title>
		<link>http://www.webxpert.ro/andrei/2010/03/14/book-review-php-5-e-commerce-development-by-michael-peacock-packt-publishing/</link>
		<comments>http://www.webxpert.ro/andrei/2010/03/14/book-review-php-5-e-commerce-development-by-michael-peacock-packt-publishing/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 17:53:19 +0000</pubDate>
		<dc:creator>andreiash</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[book review]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[michael peacock]]></category>
		<category><![CDATA[packt]]></category>

		<guid isPermaLink="false">http://www.webxpert.ro/andrei/?p=657</guid>
		<description><![CDATA[PHP is one of my preferred languages. I&#8217;ve been using it for almost 10 years, since version 3, I witnessed the release of 4.0&#8230; in some words: I have a bit of experience. I&#8217;ve been given by Packt one of the latest PHP books they published, called &#8220;PHP 5 e-Commerce Development&#8220;. The title sounds very [...]]]></description>
			<content:encoded><![CDATA[<p>PHP is one of my preferred languages. I&#8217;ve been using it for almost 10 years, since version 3, I witnessed the release of 4.0&#8230; in some words: I have a bit of experience.<br />
I&#8217;ve been given by Packt one of the latest PHP books they published, called &#8220;<a href="http://www.packtpub.com/php-5-e-commerce-development/book">PHP 5 e-Commerce Development</a>&#8220;. The title sounds very promising and I expected to get an update on the latest technologies and techniques related to e-Commerce out of it.</p>
<p><img src="http://www.webxpert.ro/andrei/wp-content/uploads/2010/03/184719964X-243x300.jpg" alt="184719964X" title="184719964X" width="243" height="300" class="aligncenter size-medium wp-image-685" /></p>
<p>First, the book is following what it says in the title, creating one e-Commerce site from the ground. From authentication to discount codes, everything is covered by the book. It touches also some APIs from payment gateways and Google. So who wants to have a ride in knowing how to build an eCommerce site with PHP 5 should read the book.</p>
<p>If you want just the positive feedback you should stop here.<span id="more-657"></span></p>
<p>Secondly, I don&#8217;t think the book has a well defined target, because author&#8217;s own framework is used all over the book and the explanations are not sufficient enough in my opinion. When there are so many frameworks on the market, it&#8217;s a very high chance that the users to use one of these frameworks (not the author&#8217;s one) to build the eShop. In this case most of the code is useless and you&#8217;ll remain just with the explanation of the logic behind. I also expected more specific info on payment processing, SEO, marketing, newsletters, admin alerts, and not necessary all the source code out there. </p>
<p>I reckon I didn&#8217;t read the description, excerpt or anything else about the book before starting to read it, so that&#8217;s why I was a bit dissapointed. The book&#8217;s description on Packt is correct: &#8220;<i>This is a fast-paced tutorial focusing on creating a framework and using it to build an online store through an ongoing case study. Later chapters include examples to illustrate how easily the framework can be adapted for different situations. The framework and code are enhanced and built upon with each chapter, adding more and more functionality. </i>&#8220;. So online store is just a case study, the book is focused on the framework.</p>
<p>However, the book is still very interesting for people that want to create their own in-house light framework and that don&#8217;t want to rely on a fat framework like CodeIgniter, phpCake, ZendFramework.</p>
<p><strong>My conclusion</strong>: a nice reading, 4 stars out of 5, but if you don&#8217;t plan to use the framework presented in the book, then the source code is too much and hard to follow. </p>
<p>****~ (4.0/5)</p>
<p>openSource e-shop solutions: <a href="http://www.prestashop.com">prestaShop</a>, <a href="http://www.oscommerce.com">osCommerce</a>.</p>
<p>Enjoy!</p>
<p><em><strong>Related posts:</strong></em></p>
<li><a href="http://www.webxpert.ro/andrei/2010/01/22/book-review-sql-developer-2-1-by-sue-harper-packt-publishing/">Book review: SQL Developer 2.1 by Sue Harper (Packt Publishing)</a></li>
<li><a href="http://www.webxpert.ro/andrei/2009/10/15/im-going-to-review-onesome-packt-books/">I&#8217;m going to review one/some Packt book(s)</a></li>
<li><a href="http://www.webxpert.ro/andrei/2009/01/14/thank-you-zendeditor/">Thank you ZendEditor !</a></li>
<li><a href="http://www.webxpert.ro/andrei/2009/01/08/thumbnail-generation-with-php-tutorial/">Thumbnail generation with PHP tutorial</a></li>
]]></content:encoded>
			<wfw:commentRss>http://www.webxpert.ro/andrei/2010/03/14/book-review-php-5-e-commerce-development-by-michael-peacock-packt-publishing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thank you ZendEditor !</title>
		<link>http://www.webxpert.ro/andrei/2009/01/14/thank-you-zendeditor/</link>
		<comments>http://www.webxpert.ro/andrei/2009/01/14/thank-you-zendeditor/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 16:21:42 +0000</pubDate>
		<dc:creator>andreiash</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[thumbnail]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://www.webxpert.ro/andrei/?p=314</guid>
		<description><![CDATA[Seems that my thumbnail generation tutorial was somehow appreciated by community and somebody posted an article on Zend Developer Zone describing my tutorial as &#8220;Advanced Thumbnail Trickery with PHP&#8220;. First, thank you! Second, I never had so many visitors coming from the same referred. When I saw my statistics I thought that my internal statistics [...]]]></description>
			<content:encoded><![CDATA[<p>Seems that my <a href="http://www.webxpert.ro/andrei/2009/01/08/thumbnail-generation-with-php-tutorial/">thumbnail generation tutorial</a> was somehow appreciated by community and somebody posted an article on Zend Developer Zone describing my tutorial as &#8220;<a href="http://devzone.zend.com/article/4162-Advanced-Thumbnail-Trickery-with-PHP">Advanced Thumbnail Trickery with PHP</a>&#8220;. </p>
<p>First, thank you!<br />
Second, I never had so many visitors coming from the same referred. When I saw my statistics I thought that my internal statistics tool went crazy and I checked my google analytics account. Seems that it&#8217;s true.</p>
<p>I promise I will elaborate the topic and make a class with it. I will also try to do the same thing with ImageMagick as a visitor suggested.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webxpert.ro/andrei/2009/01/14/thank-you-zendeditor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thumbnail generation with PHP tutorial</title>
		<link>http://www.webxpert.ro/andrei/2009/01/08/thumbnail-generation-with-php-tutorial/</link>
		<comments>http://www.webxpert.ro/andrei/2009/01/08/thumbnail-generation-with-php-tutorial/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 08:19:25 +0000</pubDate>
		<dc:creator>andreiash</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[square]]></category>
		<category><![CDATA[thumbnail]]></category>

		<guid isPermaLink="false">http://www.webxpert.ro/andrei/?p=293</guid>
		<description><![CDATA[No, it&#8217;s not yet another PHP thumbnail generation tutorial! I recently needed a function to: create square thumbnails don&#8217;t crop the initial image, but scale it and fill with white background center the thumbnail in the square call the function in a loop to process an entire folder I found no suitable example and I [...]]]></description>
			<content:encoded><![CDATA[<p>No, it&#8217;s not yet another PHP thumbnail generation tutorial! I recently needed a function to:</p>
<ul>
<li>create <strong>square </strong>thumbnails</li>
<li><strong>don&#8217;t crop</strong> the initial image, but scale it and fill with <strong>white background</strong></li>
<li><strong>center </strong>the thumbnail in the square</li>
<li>call the function in a loop to <strong>process an entire folder</strong></li>
</ul>
<p>I found no suitable example and I decided that instead of digging too much it&#8217;s better to create my own function and a class for it.</p>
<p>Let&#8217;s start with a photo that we need to create a thumbnail for:<br />
<div id="attachment_295" class="wp-caption aligncenter" style="width: 490px"><img src="http://www.webxpert.ro/andrei/wp-content/uploads/2009/01/danut.jpg" alt="Nice kid, huh?" title="danut" width="480" height="640" class="size-full wp-image-295" /><p class="wp-caption-text">Nice kid, huh?</p></div><br />
&#8230; and what we want to achieve:<br />
<img src="http://www.webxpert.ro/andrei/wp-content/uploads/2009/01/danut_thumb.jpg" alt="danut_thumb" title="danut_thumb" width="167" height="167" class="aligncenter size-full wp-image-297" /></p>
<hr />
<strong>First step would be the thumbnail generation snippet:</strong><br />
<span id="more-293"></span></p>
<div class="dean_ch" style="white-space: wrap;">
<span class="re0">$square_size</span> = <span class="nu0">167</span>;<br />
<span class="re0">$quality</span> = <span class="nu0">100</span>;<br />
<span class="co1">//get original image attributes</span><br />
<a href="http://www.php.net/list"><span class="kw3">list</span></a><span class="br0">&#40;</span><span class="re0">$width</span>, <span class="re0">$height</span>, <span class="re0">$type</span>, <span class="re0">$attr</span><span class="br0">&#41;</span> = <a href="http://www.php.net/getimagesize"><span class="kw3">getimagesize</span></a><span class="br0">&#40;</span><span class="re0">$photos_dir</span>.<span class="st0">&quot;/&quot;</span>.<span class="re0">$file</span><span class="br0">&#41;</span>;<br />
<span class="re0">$thumb</span>=imagecreatefromjpeg<span class="br0">&#40;</span><span class="re0">$photos_dir</span>.<span class="st0">&quot;/&quot;</span>.<span class="re0">$file</span><span class="br0">&#41;</span>;<br />
<span class="re0">$thumb_p</span> = imagecreatetruecolor<span class="br0">&#40;</span><span class="re0">$square_size</span>, <span class="re0">$square_size</span><span class="br0">&#41;</span>;<br />
imagecopyresampled<span class="br0">&#40;</span><span class="re0">$thumb_p</span>, <span class="re0">$thumb</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="re0">$square_size</span>, <span class="re0">$square_size</span>, <span class="re0">$width</span>, <span class="re0">$height</span><span class="br0">&#41;</span>;<br />
<span class="co1">//save the file</span><br />
imagejpeg<span class="br0">&#40;</span><span class="re0">$thumb_p</span>,<span class="re0">$thumbs_dir</span>.<span class="st0">&quot;/&quot;</span>.<span class="re0">$file</span>,<span class="re0">$quality</span><span class="br0">&#41;</span>;</div>
<p>This would be the result:<br />
<img src="http://www.webxpert.ro/andrei/wp-content/uploads/2009/01/danut1.jpg" alt="danut1" title="danut1" width="167" height="167" class="aligncenter size-full wp-image-306" /><br />
As we can see, <strong>the photo is distorted and we need to scale it</strong>, by adding 2 variables:</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="co1">//set dimensions</span><br />
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$width</span>&gt; <span class="re0">$height</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<span class="re0">$square_size</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//respect the ratio</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$height_t</span>=<a href="http://www.php.net/round"><span class="kw3">round</span></a><span class="br0">&#40;</span><span class="re0">$height</span>/<span class="re0">$width</span>*<span class="re0">$square_size</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span> <span class="kw1">elseif</span><span class="br0">&#40;</span><span class="re0">$height</span>&gt; <span class="re0">$width</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$height_t</span>=<span class="re0">$square_size</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<a href="http://www.php.net/round"><span class="kw3">round</span></a><span class="br0">&#40;</span><span class="re0">$width</span>/<span class="re0">$height</span>*<span class="re0">$square_size</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<span class="re0">$height_t</span>=<span class="re0">$square_size</span>;<br />
<span class="br0">&#125;</span></div>
<p>We also need to change the <strong>imagecopyresampled </strong>function call to add these 2 new variables:</p>
<div class="dean_ch" style="white-space: wrap;">
imagecopyresampled<span class="br0">&#40;</span><span class="re0">$thumb_p</span>, <span class="re0">$thumb</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="re0">$width_t</span>, <span class="re0">$height_t</span>, <span class="re0">$width</span>, <span class="re0">$height</span><span class="br0">&#41;</span>;</div>
<p>The new result would be:<br />
<img src="http://www.webxpert.ro/andrei/wp-content/uploads/2009/01/danut2.jpg" alt="danut2" title="danut2" width="167" height="167" class="aligncenter size-full wp-image-307" /><br />
The image is not distorted anymore but <strong>now it&#8217;s not centered</strong>. We need to move the point where the scaled image appears on the thumb to the right with a number of pixels equal to the half of the difference between height and width of the thumb. This offset is implemented also in the <strong>imagecopyresampled </strong>function, the first 2 zeros from the set of 4.</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="co1">//set dimensions</span><br />
<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$width</span>&gt; <span class="re0">$height</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<span class="re0">$square_size</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//respect the ratio</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$height_t</span>=<a href="http://www.php.net/round"><span class="kw3">round</span></a><span class="br0">&#40;</span><span class="re0">$height</span>/<span class="re0">$width</span>*<span class="re0">$square_size</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//set the offset</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_y</span>=<a href="http://www.php.net/ceil"><span class="kw3">ceil</span></a><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$width_t</span>-<span class="re0">$height_t</span><span class="br0">&#41;</span>/<span class="nu0">2</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_x</span>=<span class="nu0">0</span>;<br />
<span class="br0">&#125;</span> <span class="kw1">elseif</span><span class="br0">&#40;</span><span class="re0">$height</span>&gt; <span class="re0">$width</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$height_t</span>=<span class="re0">$square_size</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<a href="http://www.php.net/round"><span class="kw3">round</span></a><span class="br0">&#40;</span><span class="re0">$width</span>/<span class="re0">$height</span>*<span class="re0">$square_size</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="re0">$off_x</span>=<a href="http://www.php.net/ceil"><span class="kw3">ceil</span></a><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$height_t</span>-<span class="re0">$width_t</span><span class="br0">&#41;</span>/<span class="nu0">2</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_y</span>=<span class="nu0">0</span>;<br />
<span class="br0">&#125;</span><br />
<span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<span class="re0">$height_t</span>=<span class="re0">$square_size</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_x</span>=<span class="re0">$off_y</span>=<span class="nu0">0</span>;<br />
<span class="br0">&#125;</span></div>
<p>We also need to change the <strong>imagecopyresampled </strong>function call to add these 2 new variables:</p>
<div class="dean_ch" style="white-space: wrap;">
imagecopyresampled<span class="br0">&#40;</span><span class="re0">$thumb_p</span>, <span class="re0">$thumb</span>, <span class="re0">$off_x</span>, <span class="re0">$off_y</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="re0">$width_t</span>, <span class="re0">$height_t</span>, <span class="re0">$width</span>, <span class="re0">$height</span><span class="br0">&#41;</span>;</div>
<p>The new thumbnail look like this:<br />
<img src="http://www.webxpert.ro/andrei/wp-content/uploads/2009/01/danut3.jpg" alt="danut3" title="danut3" width="167" height="167" class="aligncenter size-full wp-image-308" /><br />
It&#8217;s better, the last thing I want is to <strong>set a white background to the thumb</strong> and I&#8217;m done. By default <strong>imagecreatetruecolor </strong>is creating a black canvas with no parameter to change it to white. In order to do this we need to declare a white background and fill the canvas with it <strong>BEFORE </strong>adding the scaled image:</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="re0">$bg</span> = imagecolorallocate <span class="br0">&#40;</span> <span class="re0">$thumb_p</span>, <span class="nu0">255</span>, <span class="nu0">255</span>, <span class="nu0">255</span> <span class="br0">&#41;</span>;<br />
imagefill <span class="br0">&#40;</span> <span class="re0">$thumb_p</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="re0">$bg</span> <span class="br0">&#41;</span>;</div>
<p>Now it&#8217;s what I want:<br />
<img src="http://www.webxpert.ro/andrei/wp-content/uploads/2009/01/danut4.jpg" alt="danut4" title="danut4" width="167" height="167" class="aligncenter size-full wp-image-309" /></p>
<p>The whole source code is the following:</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="kw2">function</span> set_thumb<span class="br0">&#40;</span><span class="re0">$file</span>, <span class="re0">$photos_dir</span>=<span class="st0">&#8216;uploads/photos&#8217;</span>,<span class="re0">$thumbs_dir</span>=<span class="st0">&#8216;uploads/photos/thumbs&#8217;</span>, <span class="re0">$square_size</span>=<span class="nu0">167</span>, <span class="re0">$quality</span>=<span class="nu0">100</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//check if thumb exists</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/file_exists"><span class="kw3">file_exists</span></a><span class="br0">&#40;</span><span class="re0">$thumbs_dir</span>.<span class="st0">&quot;/&quot;</span>.<span class="re0">$file</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//get image info</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/list"><span class="kw3">list</span></a><span class="br0">&#40;</span><span class="re0">$width</span>, <span class="re0">$height</span>, <span class="re0">$type</span>, <span class="re0">$attr</span><span class="br0">&#41;</span> = <a href="http://www.php.net/getimagesize"><span class="kw3">getimagesize</span></a><span class="br0">&#40;</span><span class="re0">$photos_dir</span>.<span class="st0">&quot;/&quot;</span>.<span class="re0">$file</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//set dimensions</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$width</span>&gt; <span class="re0">$height</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<span class="re0">$square_size</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//respect the ratio</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$height_t</span>=<a href="http://www.php.net/round"><span class="kw3">round</span></a><span class="br0">&#40;</span><span class="re0">$height</span>/<span class="re0">$width</span>*<span class="re0">$square_size</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//set the offset</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_y</span>=<a href="http://www.php.net/ceil"><span class="kw3">ceil</span></a><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$width_t</span>-<span class="re0">$height_t</span><span class="br0">&#41;</span>/<span class="nu0">2</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_x</span>=<span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">elseif</span><span class="br0">&#40;</span><span class="re0">$height</span>&gt; <span class="re0">$width</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$height_t</span>=<span class="re0">$square_size</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<a href="http://www.php.net/round"><span class="kw3">round</span></a><span class="br0">&#40;</span><span class="re0">$width</span>/<span class="re0">$height</span>*<span class="re0">$square_size</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_x</span>=<a href="http://www.php.net/ceil"><span class="kw3">ceil</span></a><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$height_t</span>-<span class="re0">$width_t</span><span class="br0">&#41;</span>/<span class="nu0">2</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_y</span>=<span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$width_t</span>=<span class="re0">$height_t</span>=<span class="re0">$square_size</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$off_x</span>=<span class="re0">$off_y</span>=<span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$thumb</span>=imagecreatefromjpeg<span class="br0">&#40;</span><span class="re0">$photos_dir</span>.<span class="st0">&quot;/&quot;</span>.<span class="re0">$file</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$thumb_p</span> = imagecreatetruecolor<span class="br0">&#40;</span><span class="re0">$square_size</span>, <span class="re0">$square_size</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//default background is black</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$bg</span> = imagecolorallocate <span class="br0">&#40;</span> <span class="re0">$thumb_p</span>, <span class="nu0">255</span>, <span class="nu0">255</span>, <span class="nu0">255</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imagefill <span class="br0">&#40;</span> <span class="re0">$thumb_p</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="re0">$bg</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imagecopyresampled<span class="br0">&#40;</span><span class="re0">$thumb_p</span>, <span class="re0">$thumb</span>, <span class="re0">$off_x</span>, <span class="re0">$off_y</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="re0">$width_t</span>, <span class="re0">$height_t</span>, <span class="re0">$width</span>, <span class="re0">$height</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imagejpeg<span class="br0">&#40;</span><span class="re0">$thumb_p</span>,<span class="re0">$thumbs_dir</span>.<span class="st0">&quot;/&quot;</span>.<span class="re0">$file</span>,<span class="re0">$quality</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p><em><strong>*Note</strong>: Nobody was hurt during this tutorial. The cute dude is <a href="http://rmilitaru.blogspot.com/">Razvan</a>&#8216;s son, Danut.</em></p>
<p>Read also:</p>
<li><a href="http://www.webxpert.ro/andrei/2009/01/14/thank-you-zendeditor/">Thank you ZendEditor !</a></li>
<li><a href="http://www.webxpert.ro/andrei/2010/09/09/upgrade-oracle-apex-3-2-1-to-4-0-1-on-oracle-database-10g-express-edition-xe/">Upgrade Oracle APEX 3.2.1 to 4.0.1 on Oracle Database 10g Express Edition (XE)</a></li>
<li><a href="http://www.webxpert.ro/andrei/2010/04/03/oracle-database-11g-release-2-available-on-windows-finally/">Oracle Database 11g Release 2 available on Windows&#8230; finally</a></li>
<li><a href="http://www.webxpert.ro/andrei/2010/03/14/book-review-php-5-e-commerce-development-by-michael-peacock-packt-publishing/">Book review: PHP 5 e-commerce Development by Michael Peacock (Packt Publishing)</a></li>
<li><a href="http://www.webxpert.ro/andrei/2010/03/12/install-subversion-for-vps-cpanel-under-centos/">Install subversion for VPS (cPanel) under CentOS</a></li>
]]></content:encoded>
			<wfw:commentRss>http://www.webxpert.ro/andrei/2009/01/08/thumbnail-generation-with-php-tutorial/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>How to send HTML emails via PHP</title>
		<link>http://www.webxpert.ro/andrei/2006/07/16/how-to-send-html-emails-via-php/</link>
		<comments>http://www.webxpert.ro/andrei/2006/07/16/how-to-send-html-emails-via-php/#comments</comments>
		<pubDate>Sun, 16 Jul 2006 19:47:25 +0000</pubDate>
		<dc:creator>andreiash</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.webxpert.ro/andrei/2006/07/16/how-to-send-html-emails-via-php/</guid>
		<description><![CDATA[How to send HTML emails via PHP]]></description>
			<content:encoded><![CDATA[<p>HTML emails&#8230;.. hmm, not such a good idea.<br />
I am not such a big fan of HTML emails, because I am assaulted by tens of such emails daily, most of them spam ones. And using Microsoft Outlook as email client, it ask me to download (or not) pictures from the server. This could be a bad idea sometimes, because harmful code could be be hidden in image files today (especially GIF files).</p>
<p>I was hired to make a newsletter module for one website and first I started to search how to make this.<br />
The steps are below.</p>
<p><strong>1.</strong> Create the HTML page for newsletter.<br />
<strong>2.</strong> Take care to have the CSS and JS embedded in the HTML file and not outside the file.<br />
<strong>3.</strong> Replace the relative location of image files with absolute location. E.g:<br />
if you have:<br />
[code lang="xml"]<br />
<img src="comingsoon.jpg" alt="Coming Soon"<br />
name="com_soon" width="100" height="35" border="0" id="com_soon" /><br />
[/code]<br />
you must replace with:<br />
[code lang="xml"]<br />
<img src="http://www.webxpert.ro/newsletter/comingsoon.jpg"<br />
alt="Coming Soon" name="com_soon" width="100" height="35"<br />
border="0" id="com_soon" /><br />
[/code]<br />
<span id="more-27"></span><br />
<strong>4.1.</strong> If you want to send the email by Outlook Express, you need to open a new e-mail window, choose File » New » Mail Message. Once your mail window is open, make sure the format is set to Rich Text (HTML) by choosing Format and making sure there is a highlight next to the Rich Text (HTML) line.<br />
Once your e-mail is set to Rich Text, choose View > Source Edit and you should see three tabs at the bottom of your mail message.<br />
Click the Source tab, and you&#8217;ll see the HTML source for your default e-mail message. Copy and paste all your HTML code into Outlook Express Source view.<br />
After you&#8217;ve pasted your HTML code, you can click the Preview tab to see how it will look in Outlook Express. Now all you have to do is type in your recipient&#8217;s addresses, and click &#8220;Send&#8221;.<br />
<strong>4.2.</strong> Dinamically send via PHP. First of all you must assign all the HTML to a variable. Take care to escape double quotes. Then send via mail() function like the following:<br />
[code lang="php"]<br />
<?<br />
$to = "andrei@webxpert.ro";<br />
$object = "newsletter";<br />
$from = "contact@webxpert.ro";<br />
$message="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><br />
<html xmlns=\"http://www.w3.org/1999/xhtml\"><br />
<head><br />
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" /></p>
<style type=\"text/css\">
<!--<br />
body {<br />
	background-color: #000000;<br />
	margin-top: 0px;<br />
}<br />
.normal_text {<br />
	font-family: Verdana, Arial, Helvetica, sans-serif;<br />
	font-size: 10px;<br />
}<br />
.title_text {<br />
	font-family: Verdana, Arial, Helvetica, sans-serif;<br />
	font-size: 12px;<br />
	color: #FFFFFF;<br />
}<br />
[.........................................]<br />
    </table>
</td>
</tr>
</table>
<p></body><br />
</html><br />
";</p>
<p>echo mail($to, $object, $message, "From: $from\nReply-To: $from\nContent-Type: text/html");<br />
?><br />
[/code]</p>
<p>OK, we saw how we can send a HTML email, now let's see why they are not such a good choice:</p>
<ul>
<li> Slow loading due to downloading of graphics</li>
<li> Takes up more space in your email client</li>
<li>Not all computers support html email</li>
<li>Users may not have the required bandwidth or may have download quotas set by their ISPs.</li>
<li>Hackers can send viruses, trojan horses embedded in html email.</li>
<li>Users may turn off the option to receive html email, or use filters to quarantine it. </li>
<li>It encourages people to express themselves with fancy formatting rather than with carefully chosen words.</li>
<li>If you're off-line, opening an HTML email containing images may (by default) open a connection to the internet.</li>
<li>With HTML e-mails, it's very easy to track who opened the e-mail you sent, when they opened it, and maybe even more. Imagine putting a bit of code like this into an HTML e-mail:<br />
[code lang="xml"]<br />
<img src= "http://www.spam.com/saveinfo.php?sentTo=you@yourhost.com"<br />
width=1 height="1" border="0"><br />
[/code]<br />
When the e-mail is opened, the image is fetched, but the e-mail address is sent along with the request. Now the operator knows that out of the thousands of people he spammed, this particular person opened it. In most cases, this is rude. You can gather information about someone without disclosing the practice. In fact, if you make it a tiny 1x1 image, they may not even have the clue of seeing an image in the e-mail.</li>
</ul>
<p><em><br />
Andrei<br />
<a href="http://www.webxpert.ro">http://www.webxpert.ro</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webxpert.ro/andrei/2006/07/16/how-to-send-html-emails-via-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax demystified</title>
		<link>http://www.webxpert.ro/andrei/2006/01/09/ajax-demystified/</link>
		<comments>http://www.webxpert.ro/andrei/2006/01/09/ajax-demystified/#comments</comments>
		<pubDate>Mon, 09 Jan 2006 08:30:32 +0000</pubDate>
		<dc:creator>andreiash</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.webxpert.ro/andrei/2006/01/09/ajax-demystified/</guid>
		<description><![CDATA[A small tutorial of Ajax (Asynchronous JavaScript and XML)]]></description>
			<content:encoded><![CDATA[<p>Nowadays everybody talks about <strong>Ajax</strong>. To be truly honest, I thought that is something extremely difficult, but it is not.<br />
It is no more than a programming technique (<strong>Asynchronous JavaScript and XML</strong>) in order to load external info in DIVs, without reloading the whole page (Gmail users probably knows best what I&#8217;m talking).</p>
<p>The reason why it was not widely used was that the <strong>XMLHttpRequest </strong>object is not supported by all browsers. Internet Explorer has his own object called <strong>XMLHTTP</strong> (as an ActiveX object).<br />
Since all new browsers have this facility, this technology (I think that calling this &#8220;Language&#8221; is not fair) exploded.</p>
<p>First of all we need to define some javascripts to create the object and handle the request. For this particular example, I used another javascript function to make the request.</p>
<div class="dean_ch" style="white-space: wrap;">&lt;script language=<span class="st0">&quot;javascript&quot;</span> &nbsp;type=<span class="st0">&quot;text/javascript&quot;</span>&gt;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//cross-browser object creation function</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">function</span> createRequestObject<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> ret;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//read the user&#8217;s browser </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> browser = navigator.<span class="me1">appName</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Internet Explorer has his own object</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>browser == <span class="st0">&quot;Microsoft Internet Explorer&quot;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret = <span class="kw2">new</span> ActiveXObject<span class="br0">&#40;</span><span class="st0">&quot;Microsoft.XMLHTTP&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret = <span class="kw2">new</span> XMLHttpRequest<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> ret;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//create a request object</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> http = createRequestObject<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//you will call this function</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">function</span> sendRequest<span class="br0">&#40;</span>action<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//here&#8217;s the catch &#8211; call an external page</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; http.<span class="kw3">open</span><span class="br0">&#40;</span><span class="st0">&#8216;get&#8217;</span>, <span class="st0">&#8216;req.php?action=&#8217;</span>+action<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//wait until the request is completed</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; http.<span class="me1">onreadystatechange</span> = handleResponse;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//finalize the request</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; http.<span class="me1">send</span><span class="br0">&#40;</span><span class="kw2">null</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//function that handle response state changes</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">function</span> handleResponse<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//fires only the object change to state 4</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>http.<span class="me1">readyState</span> == <span class="nu0">4</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//get the text from the external procedure</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> response = http.<span class="me1">responseText</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> update = <span class="kw2">new</span> Array<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//parse the text</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>response.<span class="me1">indexOf</span><span class="br0">&#40;</span><span class="st0">&#8216;|&#8217;</span> != <span class="nu0">-1</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//response should be &#8216;divID|value&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update = response.<span class="me1">split</span><span class="br0">&#40;</span><span class="st0">&#8216;|&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//update the element with the divID with the value</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.<span class="me1">getElementById</span><span class="br0">&#40;</span>update<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="me1">innerHTML</span> = update<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&lt;/script&gt;</p></div>
<p>After this we need to call sendRequest function from HTML, just like this:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="sc2"><a href="http://december.com/html/4/element/a.html"><span class="kw2">&lt;a</span></a> <span class="kw3">href</span>=<span class="st0">&quot;javascript:sendRequest(&#8216;currentDateTime&#8217;)&quot;</span><span class="kw2">&gt;</span></span>update time<span class="sc2"><span class="kw2">&lt;/a&gt;</span></span></div>
<p>As you see, this example get the date from an external script (req.php), and return a string with the id of the DIV that will be updated and the value of the DIV, separated by a pipe:<br />
Below is the entire code from req.php. It&#8217;s easy, don&#8217;t it?</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?</span><br />
&nbsp; <span class="co1">//test the action from request</span><br />
&nbsp; <span class="kw1">switch</span><span class="br0">&#40;</span><span class="re0">$_REQUEST</span><span class="br0">&#91;</span><span class="st0">&#8216;action&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> <span class="st0">&#8216;currentDateTime&#8217;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//return the divID and the value separated by a pipe</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&quot;currentDateTime|&quot;</span>.<a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;d/m/Y h:i:s&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;<br />
&nbsp; <span class="br0">&#125;</span><br />
<span class="kw2">?&gt;</span></div>
<p>In the original page we need a DIV to be filled with external info</p>
<div class="dean_ch" style="white-space: wrap;"><span class="sc2"><a href="http://december.com/html/4/element/div.html"><span class="kw2">&lt;div</span></a> <span class="kw3">id</span>=<span class="st0">&quot;currentDateTime&quot;</span><span class="kw2">&gt;</span></span><br />
<span class="sc2"><span class="kw2">&lt;/div&gt;</span></span></div>
<p>The whole code from HTML file is: </p>
<div class="dean_ch" style="white-space: wrap;">
<span class="sc2"><span class="kw2">&lt;</span> !DOCTYPE html PUBLIC <span class="st0">&quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span> <span class="st0">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;</span><span class="kw2">&gt;</span></span><br />
<span class="sc2"><a href="http://december.com/html/4/element/html.html"><span class="kw2">&lt;html</span></a> xmlns=<span class="st0">&quot;http://www.w3.org/1999/xhtml&quot;</span> <span class="kw2">&gt;</span></span><br />
<span class="sc2"><a href="http://december.com/html/4/element/head.html"><span class="kw2">&lt;head&gt;</span></a></span><br />
<span class="sc2"><a href="http://december.com/html/4/element/title.html"><span class="kw2">&lt;title&gt;</span></a></span>Ajax demystified<span class="sc2"><span class="kw2">&lt;/title&gt;</span></span><br />
<span class="sc2"><a href="http://december.com/html/4/element/style.html"><span class="kw2">&lt;style</span></a> <span class="kw3">type</span>=<span class="st0">&quot;text/css&quot;</span><span class="kw2">&gt;</span></span><br />
A {<br />
&nbsp; color: #336699;<br />
&nbsp; text-decoration: none;<br />
&nbsp; font-weight: bold; <br />
}</p>
<p>A:hover {<br />
&nbsp; color: #FF0000;<br />
&nbsp; font-weight: bold; <br />
} </p>
<p>BODY {<br />
&nbsp; font-family: Tahoma, Verdana, Arial, sans-serif;<br />
&nbsp; font-size: 12px; <br />
}</p>
<p>.mark {<br />
&nbsp; color: #FF0000;<br />
&nbsp; font-weight: bold; <br />
}<br />
<span class="sc2"><span class="kw2">&lt;/style&gt;</span></span><br />
<span class="sc2"><a href="http://december.com/html/4/element/script.html"><span class="kw2">&lt;script</span></a> <span class="kw3">language</span>=<span class="st0">&quot;javascript&quot;</span> &nbsp;<span class="kw3">type</span>=<span class="st0">&quot;text/javascript&quot;</span><span class="kw2">&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; //cross-browser object creation function<br />
&nbsp; &nbsp; &nbsp; &nbsp; function createRequestObject() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var ret;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //read the user&#8217;s browser <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var browser = navigator.appName;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Internet Explorer has his own object<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(browser == &quot;Microsoft Internet Explorer&quot;){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret = new XMLHttpRequest();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return ret;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; //create a request object<br />
&nbsp; &nbsp; &nbsp; &nbsp; var http = createRequestObject();<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; //you will call this function<br />
&nbsp; &nbsp; &nbsp; &nbsp; function sendRequest(action) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //here&#8217;s the catch &#8211; call an external page<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; http.open(&#8216;get&#8217;, &#8216;req.php?action=&#8217;+action);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //wait until the request is completed<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; http.onreadystatechange = handleResponse;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //finalize the request<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; http.send(null);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; //function that handle response state changes<br />
&nbsp; &nbsp; &nbsp; &nbsp; function handleResponse() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //fires only the object change to state 4<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(http.readyState == 4){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //get the text from the external procedure<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var response = http.responseText;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var update = new Array();<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //parse the text<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(response.indexOf(&#8216;|&#8217; != -1)) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //response should be &#8216;divID|value&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update = response.split(&#8216;|&#8217;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //update the element with the divID with the value<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.getElementById(update[0]).innerHTML = update[1];<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; }</p>
<p><span class="sc2"><span class="kw2">&lt;/script&gt;</span></span><br />
<span class="sc2"><span class="kw2">&lt;/head&gt;</span></span></p>
<p><span class="sc2"><a href="http://december.com/html/4/element/body.html"><span class="kw2">&lt;body</span></a> <span class="kw3">onload</span>=<span class="st0">&quot;javascript:sendRequest(&#8216;currentDateTime&#8217;)&quot;</span><span class="kw2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; This page shows how Ajax is working. Is is nothing fabulous here. <br />
&nbsp; &nbsp; &nbsp; &nbsp; </p>
<p>&nbsp;Click here for <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sc2"><a href="http://december.com/html/4/element/a.html"><span class="kw2">&lt;a</span></a> <span class="kw3">href</span>=<span class="st0">&quot;javascript:sendRequest(&#8216;currentDateTime&#8217;)&quot;</span><span class="kw2">&gt;</span></span>update time<span class="sc2"><span class="kw2">&lt;/a&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2"><a href="http://december.com/html/4/element/div.html"><span class="kw2">&lt;div</span></a> <span class="kw3">id</span>=<span class="st0">&quot;currentDateTime&quot;</span> <span class="kw3">class</span>=<span class="st0">&quot;mark&quot;</span><span class="kw2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2"><span class="kw2">&lt;/div&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
Nothing else but the date and time is updated.<br />
&nbsp; &nbsp; &nbsp; &nbsp; </p>
<p>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc1">&amp;copy;</span>2006 <span class="sc2"><a href="http://december.com/html/4/element/a.html"><span class="kw2">&lt;a</span></a> <span class="kw3">href</span>=<span class="st0">&quot;mailto:andrei@webxpert.ro&quot;</span><span class="kw2">&gt;</span></span>Andrei DANEASA<span class="sc2"><span class="kw2">&lt;/a&gt;</span></span><br />
<span class="sc2"><span class="kw2">&lt;/body&gt;</span></span><br />
<span class="sc2"><span class="kw2">&lt;/html&gt;</span></span></div>
<p>If you want to see this example working and test it, click <a href="/andrei/wp-content/ajax" target="_blank">here</a>. </p>
<p><em>*This is not intended to be a complete tutorial of Ajax, but it covers the main functionalities. The rest is only programmer&#8217;s imagination.</em><br />
<em><br />
Andrei<br />
<a href="http://www.webxpert.ro">http://www.webxpert.ro</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webxpert.ro/andrei/2006/01/09/ajax-demystified/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle connection and data retrieval from PHP</title>
		<link>http://www.webxpert.ro/andrei/2005/08/31/oracle-connection-and-data-retrieval-from-php/</link>
		<comments>http://www.webxpert.ro/andrei/2005/08/31/oracle-connection-and-data-retrieval-from-php/#comments</comments>
		<pubDate>Wed, 31 Aug 2005 10:41:15 +0000</pubDate>
		<dc:creator>andreiash</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.webxpert.ro/andrei/2005/08/31/oracle-connection-and-data-retrieval-from-php/</guid>
		<description><![CDATA[A small example of how you can connect to Oracle and retrieve a recordset from PHP]]></description>
			<content:encoded><![CDATA[<p>This should be a guide for Oracle data manipulation from PHP.</p>
<p>First of all, the connection:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span> <span class="re0">$ora_conn</span> = ora_logon<span class="br0">&#40;</span><span class="st0">&quot;username@instance&quot;</span>,<span class="st0">&quot;password&quot;</span><span class="br0">&#41;</span>; <span class="kw2">?&gt;</span></div>
<p>the sql string (we&#8217;ll use select in this example):</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span> <span class="re0">$sql</span> = <span class="st0">&quot;select col1, col2, col3 from table1 where 1=1&quot;</span>; <span class="kw2">?&gt;</span></div>
<p>the loop that retrieves the data and publish as a HTML table:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span><br />
<span class="re0">$ora_cur</span> = ora_do<span class="br0">&#40;</span><span class="re0">$ora_conn</span>, <span class="re0">$sql</span><span class="br0">&#41;</span>;<br />
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$ora_cur</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$numCols</span> = ora_numcols<span class="br0">&#40;</span><span class="re0">$ora_cur</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//alternative coloring</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$col1</span> = <span class="st0">&quot;#eeeeee&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$col2</span> = <span class="st0">&quot;#dddddd&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$toggle</span> = <span class="st0">&quot;#eeeeee&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">do</span> <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">$toggle</span> == <span class="re0">$col1</span>? <span class="re0">$toggle</span> = <span class="re0">$col2</span>: <span class="re0">$toggle</span> = <span class="re0">$col1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">?&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;tr bgcolor=<span class="st0">&quot;&lt;? echo $toggle;?&gt;&quot;</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td <span class="kw2">class</span>=<span class="st0">&quot;normal&quot;</span>&gt;&lt;? <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> ora_getcolumn<span class="br0">&#40;</span><span class="re0">$ora_cur</span>,<span class="nu0">0</span><span class="br0">&#41;</span>;?&gt;&lt;/td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td <span class="kw2">class</span>=<span class="st0">&quot;normal&quot;</span>&gt;&lt;? <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> ora_getcolumn<span class="br0">&#40;</span><span class="re0">$ora_cur</span>,<span class="nu0">1</span><span class="br0">&#41;</span>;?&gt;&lt;/td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td <span class="kw2">class</span>=<span class="st0">&quot;normal&quot;</span>&gt;&lt;? <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> ora_getcolumn<span class="br0">&#40;</span><span class="re0">$ora_cur</span>,<span class="nu0">2</span><span class="br0">&#41;</span>;?&gt;&lt;/td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td <span class="kw2">class</span>=<span class="st0">&quot;normal&quot;</span>&gt;&lt;? <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> ora_getcolumn<span class="br0">&#40;</span><span class="re0">$ora_cur</span>,<span class="nu0">3</span><span class="br0">&#41;</span>;?&gt;&lt;/td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">&lt;?</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">while</span> <span class="br0">&#40;</span>ora_fetch<span class="br0">&#40;</span><span class="re0">$ora_cur</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="kw2">?&gt;</span></div>
<p><em><br />
Andrei<br />
<a href="http://www.webxpert.ro">http://www.webxpert.ro</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webxpert.ro/andrei/2005/08/31/oracle-connection-and-data-retrieval-from-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

