<?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>PHP Online</title>
	<atom:link href="http://www.phponline.eu/feed" rel="self" type="application/rss+xml" />
	<link>http://www.phponline.eu</link>
	<description>Everything about PHP industry by Kirill Trescencov</description>
	<lastBuildDate>Sat, 13 Feb 2010 21:28:45 +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>Smarty caching</title>
		<link>http://www.phponline.eu/smarty-caching.html</link>
		<comments>http://www.phponline.eu/smarty-caching.html#comments</comments>
		<pubDate>Fri, 11 Dec 2009 06:20:37 +0000</pubDate>
		<dc:creator>Amaga</dc:creator>
				<category><![CDATA[Smarty 3]]></category>

		<guid isPermaLink="false">http://www.phponline.eu/?p=150</guid>
		<description><![CDATA[Smarty3 introduced a concept of template and data objects which can have a parent child relationship. For this an additional parameter &#8216;parent&#8217; was introduced which did change the parameter order of fetch and display to ($template, $parent = null, $cache_id = null, $compile_id = null) So $oSmarty-&#62;fetch ( $sTemplateName . &#8216;.tpl&#8217;, null, $iTemplateId ) should [...]]]></description>
			<content:encoded><![CDATA[<p><span><img class="alignleft size-full wp-image-153" style="margin-left: 10px;margin-right: 10px" title="smarty3" src="http://www.phponline.eu/files/smarty.png" alt="smarty3" width="197" height="51" />Smarty3 introduced a concept of template and data objects which can have a parent child relationship.<br />
For this an additional parameter &#8216;parent&#8217; was introduced which did change the parameter order of fetch and display to<br />
($template, $parent = null, $cache_id = null, $compile_id = null)</span></p>
<p>So<br />
$oSmarty-&gt;fetch ( $sTemplateName . &#8216;.tpl&#8217;, null, $iTemplateId )<br />
should work.</p>
<h2>NOCACHE attribute in include {include nocache}</h2>
<p>The &#8220;<strong>nocache</strong>&#8221; in the <strong>{include}</strong> does tell Smarty that the content of the subtemplate shall not be merged into the <strong>cache</strong> file of main.tpl. The subtemplate creates it&#8217;s own <strong>cache</strong> file (which can have nocached sections). The cached content and rendered content of the nocache sections of the subtemplate is inserted into the output of the cached main.tpl each time the page is called.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phponline.eu/smarty-caching.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A flexible array_split function</title>
		<link>http://www.phponline.eu/flexible-array_split-function.html</link>
		<comments>http://www.phponline.eu/flexible-array_split-function.html#comments</comments>
		<pubDate>Wed, 09 Dec 2009 06:47:38 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[Object Oriented PHP5]]></category>

		<guid isPermaLink="false">http://www.phponline.eu/?p=147</guid>
		<description><![CDATA[Split the given array into n number of pieces Examples]]></description>
			<content:encoded><![CDATA[<p>Split the given array into n number of pieces</p>
<p><pre class="brush: php; title: ; notranslate">&lt;br /&gt;
function array_split($array, $pieces=2) {&lt;br /&gt;
	if ($pieces &amp;amp;lt; 2)&lt;br /&gt;
		return array($array);&lt;br /&gt;
	$newCount = ceil(count($array)/$pieces);&lt;br /&gt;
	$a = array_slice($array, 0, $newCount);&lt;br /&gt;
	$b = array_split(array_slice($array, $newCount), $pieces-1);&lt;br /&gt;
	return array_merge(array($a),$b);&lt;br /&gt;
}&lt;br /&gt;
</pre></p>
<p>Examples<br />
<pre class="brush: php; title: ; notranslate">&lt;br /&gt;
$a = array(1,2,3,4,5,6,7,8,9,10);&lt;br /&gt;
array_split($a, 2);    // array(array(1,2,3,4,5), array(6,7,8,9,10))&lt;br /&gt;
array_split($a, 3);    // array(array(1,2,3,4), array(5,6,7), array(8,9,10))&lt;br /&gt;
array_split($a, 4);    // array(array(1,2,3), array(4,5,6), array(7,8), array(9,10))&lt;br /&gt;
</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phponline.eu/flexible-array_split-function.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Paypal IPN Integration Class v1.0.0</title>
		<link>http://www.phponline.eu/php-paypal-ipn-integration-class-v100.html</link>
		<comments>http://www.phponline.eu/php-paypal-ipn-integration-class-v100.html#comments</comments>
		<pubDate>Wed, 01 Jul 2009 02:15:49 +0000</pubDate>
		<dc:creator>Amaga</dc:creator>
				<category><![CDATA[Payment Gateways]]></category>

		<guid isPermaLink="false">http://www.phponline.eu/?p=142</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><pre class="brush: php; title: ; notranslate">&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
/*******************************************************************************&lt;br /&gt;
*                      PHP Paypal IPN Integration Class&lt;br /&gt;
*******************************************************************************&lt;br /&gt;
*      Author:     Micah Carrick&lt;br /&gt;
*      Email:      email@micahcarrick.com&lt;br /&gt;
*      Website:    http://www.micahcarrick.com&lt;br /&gt;
*&lt;br /&gt;
*      File:       paypal.class.php&lt;br /&gt;
*      Version:    1.0.0&lt;br /&gt;
*      Copyright:  (c) 2005 &amp;#8211; Micah Carrick&lt;br /&gt;
*                  You are free to use, distribute, and modify this software&lt;br /&gt;
*                  under the terms of the GNU General Public License.  See the&lt;br /&gt;
*                  included license.txt file.&lt;br /&gt;
*&lt;br /&gt;
*******************************************************************************&lt;br /&gt;
*  VERION HISTORY:&lt;br /&gt;
*&lt;br /&gt;
*      v1.0.0 [04.16.2005] &amp;#8211; Initial Version&lt;br /&gt;
*&lt;br /&gt;
*******************************************************************************&lt;br /&gt;
*  DESCRIPTION:&lt;br /&gt;
*&lt;br /&gt;
*      This file provides a neat and simple method to interface with paypal and&lt;br /&gt;
*      The paypal Instant Payment Notification (IPN) interface.  This file is&lt;br /&gt;
*      NOT intended to make the paypal integration &amp;#8220;plug &amp;#8216;n&amp;#8217; play&amp;#8221;. It still&lt;br /&gt;
*      requires the developer (that should be you) to understand the paypal&lt;br /&gt;
*      process and know the variables you want/need to pass to paypal to&lt;br /&gt;
*      achieve what you want.&lt;br /&gt;
*&lt;br /&gt;
*      This class handles the submission of an order to paypal aswell as the&lt;br /&gt;
*      processing an Instant Payment Notification.&lt;br /&gt;
*&lt;br /&gt;
*      This code is based on that of the php-toolkit from paypal.  I&amp;#8217;ve taken&lt;br /&gt;
*      the basic principals and put it in to a class so that it is a little&lt;br /&gt;
*      easier&amp;#8211;at least for me&amp;#8211;to use.  The php-toolkit can be downloaded from&lt;br /&gt;
*      http://sourceforge.net/projects/paypal.&lt;br /&gt;
*&lt;br /&gt;
*      To submit an order to paypal, have your order form POST to a file with:&lt;br /&gt;
*&lt;br /&gt;
*          $p = new paypal_class;&lt;br /&gt;
*          $p-&amp;gt;add_field(&amp;#8216;business&amp;#8217;, &amp;#8216;somebody@domain.com&amp;#8217;);&lt;br /&gt;
*          $p-&amp;gt;add_field(&amp;#8216;first_name&amp;#8217;, $_POST['first_name']);&lt;br /&gt;
*          &amp;#8230; (add all your fields in the same manor)&lt;br /&gt;
*          $p-&amp;gt;submit_paypal_post();&lt;br /&gt;
*&lt;br /&gt;
*      To process an IPN, have your IPN processing file contain:&lt;br /&gt;
*&lt;br /&gt;
*          $p = new paypal_class;&lt;br /&gt;
*          if ($p-&amp;gt;validate_ipn()) {&lt;br /&gt;
*          &amp;#8230; (IPN is verified.  Details are in the ipn_data() array)&lt;br /&gt;
*          }&lt;br /&gt;
*&lt;br /&gt;
*&lt;br /&gt;
*      In case you are new to paypal, here is some information to help you:&lt;br /&gt;
*&lt;br /&gt;
*      1. Download and read the Merchant User Manual and Integration Guide from&lt;br /&gt;
*         http://www.paypal.com/en_US/pdf/integration_guide.pdf.  This gives&lt;br /&gt;
*         you all the information you need including the fields you can pass to&lt;br /&gt;
*         paypal (using add_field() with this class) aswell as all the fields&lt;br /&gt;
*         that are returned in an IPN post (stored in the ipn_data() array in&lt;br /&gt;
*         this class).  It also diagrams the entire transaction process.&lt;br /&gt;
*&lt;br /&gt;
*      2. Create a &amp;#8220;sandbox&amp;#8221; account for a buyer and a seller.  This is just&lt;br /&gt;
*         a test account(s) that allow you to test your site from both the&lt;br /&gt;
*         seller and buyer perspective.  The instructions for this is available&lt;br /&gt;
*         at https://developer.paypal.com/ as well as a great forum where you&lt;br /&gt;
*         can ask all your paypal integration questions.  Make sure you follow&lt;br /&gt;
*         all the directions in setting up a sandbox test environment, including&lt;br /&gt;
*         the addition of fake bank accounts and credit cards.&lt;br /&gt;
*&lt;br /&gt;
*******************************************************************************&lt;br /&gt;
*/&lt;/p&gt;
&lt;p&gt;class paypal_class {&lt;/p&gt;
&lt;p&gt;var $last_error;                 // holds the last error encountered&lt;/p&gt;
&lt;p&gt;var $ipn_log;                    // bool: log IPN results to text file?&lt;br /&gt;
var $ipn_log_file;               // filename of the IPN log&lt;br /&gt;
var $ipn_response;               // holds the IPN response from paypal&lt;br /&gt;
var $ipn_data = array();         // array contains the POST values for IPN&lt;/p&gt;
&lt;p&gt;var $fields = array();           // array holds the fields to submit to paypal&lt;/p&gt;
&lt;p&gt;function paypal_class() {&lt;/p&gt;
&lt;p&gt;// initialization constructor.  Called when class is created.&lt;/p&gt;
&lt;p&gt;$this-&amp;gt;paypal_url = &amp;#8216;https://www.paypal.com/cgi-bin/webscr&amp;#8217;;&lt;/p&gt;
&lt;p&gt;$this-&amp;gt;last_error = &amp;#8221;;&lt;/p&gt;
&lt;p&gt;$this-&amp;gt;ipn_log_file = &amp;#8216;ipn_log.txt&amp;#8217;;&lt;br /&gt;
$this-&amp;gt;ipn_log = true;&lt;br /&gt;
$this-&amp;gt;ipn_response = &amp;#8221;;&lt;/p&gt;
&lt;p&gt;// populate $fields array with a few default values.  See the paypal&lt;br /&gt;
// documentation for a list of fields and their data types. These defaul&lt;br /&gt;
// values can be overwritten by the calling script.&lt;/p&gt;
&lt;p&gt;$this-&amp;gt;add_field(&amp;#8216;rm&amp;#8217;,&amp;#8217;2&amp;#8242;);           // Return method = POST&lt;br /&gt;
$this-&amp;gt;add_field(&amp;#8216;cmd&amp;#8217;,'_xclick&amp;#8217;);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;function add_field($field, $value) {&lt;/p&gt;
&lt;p&gt;// adds a key=&amp;gt;value pair to the fields array, which is what will be&lt;br /&gt;
// sent to paypal as POST variables.  If the value is already in the&lt;br /&gt;
// array, it will be overwritten.&lt;/p&gt;
&lt;p&gt;$this-&amp;gt;fields[&quot;$field&quot;] = $value;&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;function submit_paypal_post() {&lt;/p&gt;
&lt;p&gt;// this function actually generates an entire HTML page consisting of&lt;br /&gt;
// a form with hidden elements which is submitted to paypal via the&lt;br /&gt;
// BODY element&amp;#8217;s onLoad attribute.  We do this so that you can validate&lt;br /&gt;
// any POST vars from you custom form before submitting to paypal.  So&lt;br /&gt;
// basically, you&amp;#8217;ll have your own form which is submitted to your script&lt;br /&gt;
// to validate the data, which in turn calls this function to create&lt;br /&gt;
// another hidden form and submit to paypal.&lt;/p&gt;
&lt;p&gt;// The user will briefly see a message on the screen that reads:&lt;br /&gt;
// &amp;#8220;Please wait, your order is being processed&amp;#8230;&amp;#8221; and then immediately&lt;br /&gt;
// is redirected to paypal.&lt;/p&gt;
&lt;p&gt;echo &amp;#8220;&amp;lt;html&amp;gt;\n&amp;#8221;;&lt;br /&gt;
echo &amp;#8220;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Processing Payment&amp;#8230;&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;\n&amp;#8221;;&lt;br /&gt;
echo &amp;#8220;&amp;lt;body onLoad=\&amp;#8221;document.form.submit();\&amp;#8221;&amp;gt;\n&amp;#8221;;&lt;br /&gt;
echo &amp;#8220;&amp;lt;center&amp;gt;&amp;lt;h3&amp;gt;Please wait, your order is being processed&amp;#8230;&amp;lt;/h3&amp;gt;&amp;lt;/center&amp;gt;\n&amp;#8221;;&lt;br /&gt;
echo &amp;#8220;&amp;lt;form method=\&amp;#8221;post\&amp;#8221; name=\&amp;#8221;form\&amp;#8221; action=\&amp;#8221;&quot;.$this-&amp;gt;paypal_url.&amp;#8221;\&amp;#8221;&amp;gt;\n&amp;#8221;;&lt;/p&gt;
&lt;p&gt;foreach ($this-&amp;gt;fields as $name =&amp;gt; $value) {&lt;br /&gt;
echo &amp;#8220;&amp;lt;input type=\&amp;#8221;hidden\&amp;#8221; name=\&amp;#8221;$name\&amp;#8221; value=\&amp;#8221;$value\&amp;#8221;&amp;gt;&amp;#8221;;&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;echo &amp;#8220;&amp;lt;/form&amp;gt;\n&amp;#8221;;&lt;br /&gt;
echo &amp;#8220;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;\n&amp;#8221;;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;function validate_ipn() {&lt;/p&gt;
&lt;p&gt;// parse the paypal URL&lt;br /&gt;
$url_parsed=parse_url($this-&amp;gt;paypal_url);&lt;/p&gt;
&lt;p&gt;// generate the post string from the _POST vars aswell as load the&lt;br /&gt;
// _POST vars into an arry so we can play with them from the calling&lt;br /&gt;
// script.&lt;br /&gt;
$post_string = &amp;#8221;;&lt;br /&gt;
foreach ($_POST as $field=&amp;gt;$value) {&lt;br /&gt;
$this-&amp;gt;ipn_data[&quot;$field&quot;] = $value;&lt;br /&gt;
$post_string .= $field.&amp;#8217;=&amp;#8217;.urlencode($value).&amp;#8217;&amp;amp;&amp;#8217;;&lt;br /&gt;
}&lt;br /&gt;
$post_string.=&amp;#8221;cmd=_notify-validate&amp;#8221;; // append ipn command&lt;/p&gt;
&lt;p&gt;// open the connection to paypal&lt;br /&gt;
$fp = fsockopen($url_parsed[host],&amp;#8221;80&amp;#8243;,$err_num,$err_str,30);&lt;br /&gt;
if(!$fp) {&lt;/p&gt;
&lt;p&gt;// could not open the connection.  If loggin is on, the error message&lt;br /&gt;
// will be in the log.&lt;br /&gt;
$this-&amp;gt;last_error = &amp;#8220;fsockopen error no. $errnum: $errstr&amp;#8221;;&lt;br /&gt;
$this-&amp;gt;log_ipn_results(false);&lt;br /&gt;
return false;&lt;/p&gt;
&lt;p&gt;} else {&lt;/p&gt;
&lt;p&gt;// Post the data back to paypal&lt;br /&gt;
fputs($fp, &amp;#8220;POST $url_parsed[path] HTTP/1.1\r\n&amp;#8221;);&lt;br /&gt;
fputs($fp, &amp;#8220;Host: $url_parsed[host]\r\n&amp;#8221;);&lt;br /&gt;
fputs($fp, &amp;#8220;Content-type: application/x-www-form-urlencoded\r\n&amp;#8221;);&lt;br /&gt;
fputs($fp, &amp;#8220;Content-length: &amp;#8220;.strlen($post_string).&amp;#8221;\r\n&amp;#8221;);&lt;br /&gt;
fputs($fp, &amp;#8220;Connection: close\r\n\r\n&amp;#8221;);&lt;br /&gt;
fputs($fp, $post_string . &amp;#8220;\r\n\r\n&amp;#8221;);&lt;/p&gt;
&lt;p&gt;// loop through the response from the server and append to variable&lt;br /&gt;
while(!feof($fp)) {&lt;br /&gt;
$this-&amp;gt;ipn_response .= fgets($fp, 1024);&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;fclose($fp); // close connection&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;if (eregi(&amp;#8220;VERIFIED&amp;#8221;,$this-&amp;gt;ipn_response)) {&lt;/p&gt;
&lt;p&gt;// Valid IPN transaction.&lt;br /&gt;
$this-&amp;gt;log_ipn_results(true);&lt;br /&gt;
return true;&lt;/p&gt;
&lt;p&gt;} else {&lt;/p&gt;
&lt;p&gt;// Invalid IPN transaction.  Check the log for details.&lt;br /&gt;
$this-&amp;gt;last_error = &amp;#8216;IPN Validation Failed.&amp;#8217;;&lt;br /&gt;
$this-&amp;gt;log_ipn_results(false);&lt;br /&gt;
return false;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;function log_ipn_results($success) {&lt;/p&gt;
&lt;p&gt;if (!$this-&amp;gt;ipn_log) return;  // is logging turned off?&lt;/p&gt;
&lt;p&gt;// Timestamp&lt;br /&gt;
$text = &amp;#8216;['.date('m/d/Y g:i A').'] &amp;#8211; &amp;#8216;;&lt;/p&gt;
&lt;p&gt;// Success or failure being logged?&lt;br /&gt;
if ($success) $text .= &amp;#8220;SUCCESS!\n&amp;#8221;;&lt;br /&gt;
else $text .= &amp;#8216;FAIL: &amp;#8216;.$this-&amp;gt;last_error.&amp;#8221;\n&amp;#8221;;&lt;/p&gt;
&lt;p&gt;// Log the POST variables&lt;br /&gt;
$text .= &amp;#8220;IPN POST Vars from Paypal:\n&amp;#8221;;&lt;br /&gt;
foreach ($this-&amp;gt;ipn_data as $key=&amp;gt;$value) {&lt;br /&gt;
$text .= &amp;#8220;$key=$value, &amp;#8220;;&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;// Log the response from the paypal server&lt;br /&gt;
$text .= &amp;#8220;\nIPN Response from Paypal Server:\n &amp;#8220;.$this-&amp;gt;ipn_response;&lt;/p&gt;
&lt;p&gt;// Write to log&lt;br /&gt;
$fp=fopen($this-&amp;gt;ipn_log_file,&amp;#8217;a');&lt;br /&gt;
fwrite($fp, $text . &amp;#8220;\n\n&amp;#8221;);&lt;/p&gt;
&lt;p&gt;fclose($fp);  // close file&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;function dump_fields() {&lt;/p&gt;
&lt;p&gt;// Used for debugging, this function will output all the field/value pairs&lt;br /&gt;
// that are currently defined in the instance of the class using the&lt;br /&gt;
// add_field() function.&lt;/p&gt;
&lt;p&gt;echo &amp;#8220;&amp;lt;h3&amp;gt;paypal_class-&amp;gt;dump_fields() Output:&amp;lt;/h3&amp;gt;&amp;#8221;;&lt;br /&gt;
echo &amp;#8220;&amp;lt;table width=\&amp;#8221;95%\&amp;#8221; border=\&amp;#8221;1\&amp;#8221; cellpadding=\&amp;#8221;2\&amp;#8221; cellspacing=\&amp;#8221;0\&amp;#8221;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td bgcolor=\&amp;#8221;black\&amp;#8221;&amp;gt;&amp;lt;b&amp;gt;&amp;lt;font color=\&amp;#8221;white\&amp;#8221;&amp;gt;Field Name&amp;lt;/font&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td bgcolor=\&amp;#8221;black\&amp;#8221;&amp;gt;&amp;lt;b&amp;gt;&amp;lt;font color=\&amp;#8221;white\&amp;#8221;&amp;gt;Value&amp;lt;/font&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;#8221;;&lt;/p&gt;
&lt;p&gt;ksort($this-&amp;gt;fields);&lt;br /&gt;
foreach ($this-&amp;gt;fields as $key =&amp;gt; $value) {&lt;br /&gt;
echo &amp;#8220;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;$key&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;#8221;.urldecode($value).&amp;#8221; &amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;#8221;;&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;echo &amp;#8220;&amp;lt;/table&amp;gt;&amp;lt;br&amp;gt;&amp;#8221;;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phponline.eu/php-paypal-ipn-integration-class-v100.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery &#8211; Simplified database queries</title>
		<link>http://www.phponline.eu/jquery-simplified-database-queries.html</link>
		<comments>http://www.phponline.eu/jquery-simplified-database-queries.html#comments</comments>
		<pubDate>Wed, 17 Jun 2009 08:46:59 +0000</pubDate>
		<dc:creator>Amaga</dc:creator>
				<category><![CDATA[Code Library]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Other]]></category>
		<category><![CDATA[Shopping Carts]]></category>

		<guid isPermaLink="false">http://www.phponline.eu/?p=124</guid>
		<description><![CDATA[A function to perform database queries on MySQL servers. Takes one argument; The SQL statement.]]></description>
			<content:encoded><![CDATA[<p>A function to perform database queries on MySQL servers. Takes one argument; The SQL statement.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phponline.eu/jquery-simplified-database-queries.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web development common fonts to Windows &amp; Mac</title>
		<link>http://www.phponline.eu/web-development-common-fonts-to-windows-mac.html</link>
		<comments>http://www.phponline.eu/web-development-common-fonts-to-windows-mac.html#comments</comments>
		<pubDate>Wed, 17 Jun 2009 05:22:38 +0000</pubDate>
		<dc:creator>Amaga</dc:creator>
				<category><![CDATA[HTML / CSS]]></category>

		<guid isPermaLink="false">http://www.phponline.eu/?p=85</guid>
		<description><![CDATA[[style] p { margin: 10px 0; } table { width: 100%; margin: 0 0 10px; border: 2px solid Black; } caption { padding: 20px 0 5px; margin: 0; font: normal bold 1.35em Arial, Helvetica, sans-serif; text-align: left; color: Black; } th { padding: 2px 0; border: 1px solid Black; border-bottom-width: 3px; font: normal bold 1.15em [...]]]></description>
			<content:encoded><![CDATA[
[style]
p { margin: 10px 0; }
table {
width: 100%;
margin: 0 0 10px;
border: 2px solid Black;
}
caption {
padding: 20px 0 5px;
margin: 0;
font: normal bold 1.35em Arial, Helvetica, sans-serif;
text-align: left;
color: Black;
}
th {
padding: 2px 0;
border: 1px solid Black;
border-bottom-width: 3px;
font: normal bold 1.15em Arial, Helvetica, sans-serif;
}
td {
padding: 5px 20px;
border: 1px solid Silver;
font-size: 1.2em;
}
.bold { font-weight: bold; }
td+td { font-weight: bold; } /* Mozilla only supports W3C defined properties for  */
em {
color: Gray;
font-style: italic;
}
.symbol { font-size: 0.8em; }
.mac { color: SteelBlue; }
.mac a { color: MidnightBlue; }
.notes {
font-style: italic;
margin-bottom: 30px;
}
[/style]


Here you can find the list with the standard set of fonts common to all versions of Windows and their Mac substitutes, referred sometimes as "browser safe fonts". This is the reference I use when making web pages and I expect you will find it useful too.
<span id="more-85"></span>
<br /><br />
First, a few introductory notes:
<br /><br />
The names in grey are the generic family of each font.
<br /><br />
In some cases the Mac equivalent is the same font, since Mac OS X also includes some of the fonts shipped with Windows.
<br /><br />
The notes at the bottom contains specific information about some of the fonts.
<br />
<table border="0" cellspacing="0"><caption>Windows fonts / <span class="mac">Mac fonts</span> / <em>Font family</em></caption>

<col></col>

<col></col>
<tbody>
<tr>
<th class="center">Normal style</th>
<th class="center">Bold style</th>
</tr>
<tr style="font-family: Arial, Helvetica, sans-serif">
<td>Arial, <span class="mac">Arial, Helvetica</span>, <em>sans-serif</em></td>
<td>Arial, <span class="mac">Arial, Helvetica</span>, <em>sans-serif</em></td>
</tr>
<tr style="font-family: 'Arial Black', Gadget, sans-serif">
<td>Arial Black, <span class="mac">Arial Black, Gadget</span>, <em>sans-serif</em></td>
<td>Arial Black, <span class="mac">Arial Black, Gadget</span>, <em>sans-serif</em></td>
</tr>
<tr style="font-family: 'Comic Sans MS', Textile, cursive">
<td>Comic Sans MS, <span class="mac">Comic Sans MS<sup>5</sup></span>, <em>cursive</em></td>
<td>Comic Sans MS, <span class="mac">Comic Sans MS<sup>5</sup></span>, <em>cursive</em></td>
</tr>
<tr style="font-family: 'Courier New', Courier, monospace">
<td>Courier New, <span class="mac">Courier New, Courier<sup>6</sup></span>, <em>monospace</em></td>
<td>Courier New, <span class="mac">Courier New, Courier<sup>6</sup></span>, <em>monospace</em></td>
</tr>
<tr style="font-family: Georgia, 'Times New Roman', Times, serif">
<td>Georgia<sup>1</sup>, <span class="mac">Georgia</span>, <em>serif</em></td>
<td>Georgia<sup>1</sup>, <span class="mac">Georgia</span>, <em>serif</em></td>
</tr>
<tr style="font-family: Impact, Charcoal, sans-serif">
<td>Impact, <span class="mac">Impact<sup>5</sup>, Charcoal<sup>6</sup></span>, <em>sans-serif</em></td>
<td>Impact, <span class="mac">Impact<sup>5</sup>, Charcoal<sup>6</sup></span>, <em>sans-serif</em></td>
</tr>
<tr style="font-family: 'Lucida Console', Monaco, monospace">
<td>Lucida Console, <span class="mac">Monaco<sup>5</sup></span>, <em>monospace</em></td>
<td>Lucida Console, <span class="mac">Monaco<sup>5</sup></span>, <em>monospace</em></td>
</tr>
<tr style="font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif">
<td>Lucida Sans Unicode, <span class="mac">Lucida Grande</span>, <em>sans-serif</em></td>
<td>Lucida Sans Unicode, <span class="mac">Lucida Grande</span>, <em>sans-serif</em></td>
</tr>
<tr style="font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, serif">
<td>Palatino Linotype, Book Antiqua<sup>3</sup>, <span class="mac">Palatino<sup>6</sup></span>, <em>serif</em></td>
<td>Palatino Linotype, Book Antiqua<sup>3</sup>, <span class="mac">Palatino<sup>6</sup></span>, <em>serif</em></td>
</tr>
<tr style="font-family: Tahoma, Geneva, sans-serif">
<td>Tahoma, <span class="mac">Geneva</span>, <em>sans-serif</em></td>
<td>Tahoma, <span class="mac">Geneva</span>, <em>sans-serif</em></td>
</tr>
<tr style="font-family: 'Times New Roman', Times, serif">
<td>Times New Roman, <span class="mac">Times</span>, <em>serif</em></td>
<td>Times New Roman, <span class="mac">Times</span>, <em>serif</em></td>
</tr>
<tr style="font-family: 'Trebuchet MS', Helvetica, sans-serif">
<td>Trebuchet MS<sup>1</sup>, <span class="mac">Helvetica</span>, <em>sans-serif</em></td>
<td>Trebuchet MS<sup>1</sup>, <span class="mac">Helvetica</span>, <em>sans-serif</em></td>
</tr>
<tr style="font-family: Verdana, Geneva, sans-serif">
<td>Verdana, <span class="mac">Verdana, Geneva</span>, <em>sans-serif</em></td>
<td>Verdana, <span class="mac">Verdana, Geneva</span>, <em>sans-serif</em></td>
</tr>
<tr class="symbol" style="font-family: Symbol">
<td>Symbol, <span class="mac">Symbol</span> <span style="font-family: Verdana">(Symbol<sup>2</sup>, <span class="mac">Symbol<sup>2</sup></span>)</span></td>
<td>Symbol, <span class="mac">Symbol</span> <span style="font-family: Verdana">(Symbol<sup>2</sup>, <span class="mac">Symbol<sup>2</sup></span>)</span></td>
</tr>
<tr class="symbol" style="font-family: Webdings">
<td>Webdings, <span class="mac">Webdings</span> <span style="font-family: Verdana">(Webdings<sup>2</sup>, <span class="mac">Webdings<sup>2</sup></span>)</span></td>
<td>Webdings, <span class="mac">Webdings</span> <span style="font-family: Verdana">(Webdings<sup>2</sup>, <span class="mac">Webdings<sup>2</sup></span>)</span></td>
</tr>
<tr class="symbol" style="font-family: Wingdings, 'Zapf Dingbats'">
<td>Wingdings, <span class="mac">Zapf Dingbats</span> <span style="font-family: Verdana">(Wingdings<sup>2</sup>, <span class="mac">Zapf Dingbats<sup>2</sup></span>)</span></td>
<td>Wingdings, <span class="mac">Zapf Dingbats</span> <span style="font-family: Verdana">(Wingdings<sup>2</sup>, <span class="mac">Zapf Dingbats<sup>2</sup></span>)</span></td>
</tr>
<tr style="font-family: 'MS Sans Serif', Geneva, sans-serif">
<td>MS Sans Serif<sup>4</sup>, <span class="mac">Geneva</span>, <em>sans-serif</em></td>
<td>MS Sans Serif<sup>4</sup>, <span class="mac">Geneva</span>, <em>sans-serif</em></td>
</tr>
<tr style="font-family: 'MS Serif', 'New York', serif">
<td>MS Serif<sup>4</sup>, <span class="mac">New York<sup>6</sup></span>, <em>serif</em></td>
<td>MS Serif<sup>4</sup>, <span class="mac">New York<sup>6</sup></span>, <em>serif</em></td>
</tr>
</tbody></table>

<div class="notes">
  <p><sup>1</sup> Georgia and Trebuchet MS are bundled with Windows 2000/XP and they are
  also included in the IE font pack (and bundled with other MS applications), so they
  are quite common in Windows 98 systems.</p>

  <p><sup>2</sup> Symbolic fonts are only displayed in Internet Explorer, in other browsers a
  font substitute is used instead (although the Symbol font does work in Opera and the Webdings
  works in Safari).</p>
  <p><sup>3</sup> Book Antiqua is almost exactly the same font that Palatino Linotype, Palatino Linotype
  is included in Windows 2000/XP while Book Antiqua was bundled with Windows 98.</p>
  <p><sup>4</sup> These fonts are not TrueType fonts but bitmap fonts, so they won't
  look well when using some font sizes (they are designed for 8, 10, 12, 14, 18 and 24 point
  sizes at 96 DPI).</p>
  <p class="mac"><sup>5</sup> These fonts work in Safari but only when using the normal font style,
  and not with bold or italic styles. Comic Sans MS works in bold but not in italic. Other Mac
  browsers seems to emulate properly the styles not provided by the font (thanks to <a class="external" target="_blank" href="http://christianfecteau.com/">Christian Fecteau</a> for the tip).</p>

  <p class="mac"><sup>6</sup> These fonts are present in Mac OS X only if <strong>Classic</strong> is
  installed.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.phponline.eu/web-development-common-fonts-to-windows-mac.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>30 Tips to optimizing php code</title>
		<link>http://www.phponline.eu/tips-for-optimizing-your-php-code.html</link>
		<comments>http://www.phponline.eu/tips-for-optimizing-your-php-code.html#comments</comments>
		<pubDate>Wed, 10 Jun 2009 05:34:16 +0000</pubDate>
		<dc:creator>Amaga</dc:creator>
				<category><![CDATA[PHP4 / PHP5]]></category>

		<guid isPermaLink="false">http://www.phponline.eu/?p=49</guid>
		<description><![CDATA[PHP is a very fast programming language, but there is more to optimizing PHP than just speed of code execution. Here is the list of 30 short tips you can use for writing an optimized and more efficient PHP code. I considered myself a bit of a PHP pro until I started researching some of [...]]]></description>
			<content:encoded><![CDATA[<strong>PHP</strong> is a very fast programming language, but there is more to optimizing PHP than just speed of code execution. Here is the list of 30 short tips you can use for writing an optimized and more efficient PHP code. I considered myself a bit of a PHP pro until I started researching some of this stuff and realized that there is a whole realm of information out there about optimizing php that I didn’t know about. I hope you will be as surprised as I was about some of the things you might learn from this article.<span id="more-49"></span>
<ol>
	<li>If a method can be static, declare it static. Speed improvement is by a factor of 4.</li>
	<li><em>echo</em> is faster than <em>print</em>.</li>
	<li>Unset your large variables to free memory.</li>
	<li>require_once() is expensive</li>
	<li>Use full paths in includes and requires, less time spent on resolving the OS paths.</li>
	<li>If you need to find out the time when the script started executing, $_SERVER[’REQUEST_TIME’] is preferred to time()</li>
	<li>See if you can use strncasecmp, strpbrk and stripos instead of regex</li>
	<li>str_replace is faster than preg_replace, but strtr is faster than str_replace by a factor of 4</li>
	<li>If the function, such as string replacement function, accepts both arrays and single characters as arguments, and if your argument list is not too long, consider writing a few redundant replacement statements, passing one character at a time, instead of one line of code that accepts arrays as search and replace arguments.</li>
	<li>It's better to use switch statements than multi if, else if, statements.</li>
	<li>Error suppression with @ is very slow.</li>
	<li>Turn on apache's mod_deflate</li>
	<li>$row[’id’] is 7 times faster than $row[id]</li>
	<li>Do not use functions inside of for loop, such as for ($x=0; $x &lt; count($array); $x) The count() function gets called each time.</li>
	<li>Incrementing a local variable in a method is the fastest. Nearly the same as calling a local variable in a function.</li>
	<li>Incrementing a global variable is 2 times slow than a local var.</li>
	<li>Incrementing an object property (eg. $this-&gt;prop++) is 3 times slower than a local variable.</li>
	<li>Incrementing an undefined local variable is 9-10 times slower than a pre-initialized one.</li>
	<li>Just declaring a global variable without using it in a function also slows things down (by about the same amount as incrementing a local var). PHP probably does a check to see if the global exists.</li>
	<li>Method invocation appears to be independent of the number of methods defined in the class because I added 10 more methods to the test class (before and after the test method) with no change in performance.</li>
	<li>Methods in derived classes run faster than ones defined in the base class.</li>
	<li>A function call with one parameter and an empty function body takes about the same time as doing 7-8 $localvar++ operations. A similar method call is of course about 15 $localvar++ operations.</li>
	<li>Surrounding your string by ' instead of " will make things interpret a little faster since php looks for variables inside "..." but not inside '...'. Of course you can only do this when you don't need to have variables in the string.</li>
	<li>A PHP script will be served at least 2-10 times slower than a static HTML page by Apache. Try to use more static HTML pages and fewer scripts.</li>
	<li>Your PHP scripts are recompiled every time unless the scripts are cached. Install a PHP caching product to typically increase performance by 25-100% by removing compile times. Cache as much as possible. Use memcached - memcached is a high-performance memory object caching system intended to speed up dynamic web applications by alleviating database load. OP code caches are useful so that your script does not have to be compiled on every request.</li>
	<li>When incrementing or decrementing the value of the variable $i++ happens to be a tad slower then ++$i. This is something PHP specific and does not apply to other languages, so don't go modifying your C or Java code thinking it'll suddenly become faster, it won't. ++$i happens to be faster in PHP because instead of 4 opcodes used for $i++ you only need 3. Post incrementation actually causes in the creation of a temporary var that is then incremented. While pre-incrementation increases the original value directly. This is one of the optimization that opcode optimized like Zend's PHP optimizer. It is a still a good idea to keep in mind since not all opcode optimizers perform this optimization and there are plenty of ISPs and servers running without an opcode optimizer.</li>
	<li>Not everything has to be OOP, often it is too much overhead, each method and object call consumes a lot of memory.</li>
	<li>Do not implement every data structure as a class, arrays are useful, too</li>
	<li>Don't split methods too much, think, which code you will really re-use</li>
	<li>Make use of the countless predefined functions</li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://www.phponline.eu/tips-for-optimizing-your-php-code.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sessions</title>
		<link>http://www.phponline.eu/sessions.html</link>
		<comments>http://www.phponline.eu/sessions.html#comments</comments>
		<pubDate>Tue, 15 Apr 2008 07:55:48 +0000</pubDate>
		<dc:creator>Amaga</dc:creator>
				<category><![CDATA[Classes]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[sessions]]></category>

		<guid isPermaLink="false">http://www.phponline.eu/?p=44</guid>
		<description><![CDATA[PHP Sessions - Why Use Them? A session is a way to store information (in the form of variables) to be used across multiple pages. Unlike a cookie, specific variable information is not stored on the users computer. It is also unlike other variables in the sense that we are not passing them individually to [...]]]></description>
			<content:encoded><![CDATA[<h2>PHP Sessions - Why Use Them?</h2>
A session is a way to store information (in the form of variables) to be used across multiple pages.  Unlike a cookie, specific variable information is not stored on the users computer. It is also unlike other variables in the sense that we are not passing them individually to each new page, but instead retrieving them from the session we open at beginning of each page.

Start a PHP Session

Before you can begin storing user information in your PHP session, you must first start the session.  When you start a session, it must be at the very beginning of your code, before any HTML or text is sent.

Below is a simple script that you should place at the beginning of your PHP code to start up a PHP session.

<pre class="brush: php; title: ; notranslate">
session_start(); // start up your PHP session!
</pre>

This tiny piece of code will register the user's session with the server, allow you to start saving user information and assign a UID (unique identification number) for that user's session.
<span id="more-44"></span>
<h2>Storing a Session Variable</h2>
When you want to store user data in a session use the $_SESSION associative array. This is where you both store and retrieve session data. In previous versions of PHP there were other ways to perform this store operation, but it has been updated and this is the correct way to do it.
<pre class="brush: php; title: ; notranslate">
session_start();
$_SESSION['views'] = 1; // store session data
echo &quot;Pageviews = &quot;. $_SESSION['views']; //retrieve data
</pre>

<strong>Display</strong>
<pre class="brush: xml; title: ; notranslate">
Pageviews = 1
</pre>

In this example we learned how to store a variable to the session associative array $_SESSION and also how to retrieve data from that same array.
<h2>PHP Sessions: Using PHP's isset Function</h2>
Now that you are able to store and retrieve data from the $_SESSION array, we can explore some of the real functionality of sessions. When you create a variable and store it in a session, you probably want to use it in the future. However, before you use a session variable it is necessary that you check to see if it exists already!

This is where PHP's isset function comes in handy. isset is a function that takes any variable you want to use and checks to see if it has been set. That is, it has already been assigned a value.

With our previous example, we can create a very simple pageview counter by using isset to check if the pageview variable has already been created. If it has we can increment our counter. If it doesn't exist we can create a pageview counter and set it to one. Here is the code to get this job done:
<pre class="brush: php; title: ; notranslate">
session_start();
if(isset($_SESSION['views']))
$_SESSION['views'] = $_SESSION['views']+ 1;
else
$_SESSION['views'] = 1;

echo &quot;views = &quot;. $_SESSION['views'];
</pre>
The first time you run this script on a freshly opened browser the if statement will fail because no session variable views would have been stored yet. However, if you were to refresh the page the if statement would be true and the counter would increment by one. Each time you reran this script you would see an increase in view by one.
<h2>Cleaning and Destroying your Session</h2>
Although a session's data is temporary and does not require that you explicitly clean after yourself, you may wish to delete some data for your various tasks.

Imagine that you were running an online business and a user used your website to buy your goods. The user has just completed a transaction on your website and you now want to remove everything from their shopping cart.
<pre class="brush: php; title: ; notranslate">
session_start();
if(isset($_SESSION['cart']))
unset($_SESSION['cart']);
</pre>
You can also completely destroy the session entirely by calling the session_destroy function.
<pre class="brush: php; title: ; notranslate">
session_start();
session_destroy();
</pre>
Destroy will reset your session, so don't call that function unless you are entirely comfortable losing all your stored session data!]]></content:encoded>
			<wfw:commentRss>http://www.phponline.eu/sessions.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

