Warning: Creating default object from empty value in /home/webstorm/public_html/w4schools.org/engine/classes/feed.php on line 26

Warning: Cannot modify header information - headers already sent by (output started at /home/webstorm/public_html/w4schools.org/engine/classes/feed.php:26) in /home/webstorm/public_html/w4schools.org/engine/classes/feed.php on line 108
Web development tutorials for PHP, HTML, CSS, JS and jQueryhttp://www.w4schools.org/feed/PHP, HTML, CSS, JS, jQuery tutorials, examples and free code. Free web development features. Free downloadable code and easy to use tools for developers.en-usCopyright 2010-1013 - All rights reservedJquery grayscalehttp://www.w4schools.org/jquery-grayscale-13.htmlThe following example is using Jquery and it should work in all browsers but only for images. <br /><br /> A full working demo can be downloaded from <a class="lightblue" href="http://w4schools.org/downloads/jquery-grayscale/jquery-grayscale.zip">here</a> <br /> <br /> &lt;p&gt;Grayscale&lt;/p&gt;<br /> &lt;img src=&quot;img/logo.png&quot; class=&quot;grayscale&quot; alt=&quot;grayscale demo&quot; /&gt;<br /> &lt;br /&gt;<br /> &lt;p&gt;No grayscale&lt;/p&gt;<br /> &lt;img src=&quot;img/logo.png&quot; alt=&quot;no grayscale image demo&quot; /&gt;<br /> &lt;br /&gt;<br /> &lt;script type=&quot;text/javascript&quot;&gt;<br /> <br /> function grayscale(src){<br /> <br /> var graycanvas = document.createElement('canvas');<br /> var ctx = graycanvas .getContext('2d');<br /> var imgObj = new Image();<br /> imgObj.src = src;<br /> graycanvas .width = imgObj.width;<br /> graycanvas .height = imgObj.height; <br /> ctx.drawImage(imgObj, 0, 0); <br /> var canvasPixels = ctx.getImageData(0, 0, graycanvas .width, graycanvas .height);<br /> <br /> for(var y = 0; y &amp;lt; canvasPixels.height; y++){<br /> for(var x = 0; x &amp;lt; canvasPixels.width; x++){<br /> <br /> var i = (y * 4) * canvasPixels.width + x * 4;<br /> var average= (canvasPixels.data[i] + canvasPixels.data[i + 1] + canvasPixels.data[i + 2]) / 3;<br /> canvasPixels.data[i] = average; <br /> canvasPixels.data[i + 1] = average; <br /> canvasPixels.data[i + 2] = average;<br /> }<br /> }<br /> ctx.putImageData(canvasPixels, 0, 0, 0, 0, canvasPixels.width, canvasPixels.height);<br /> return graycanvas .toDataURL();<br /> }<br /> <br /> (function($) {<br /> $.fn.grayScale = function()<br /> { <br /> var elem=$(this);<br /> var source=elem.attr('src');<br /> elem.attr(&quot;src&quot;,grayscale(source));<br /> }<br /> })(jQuery);<br /> <br /> // usage $(selector).grayScale();<br /> $('img.grayscale').grayScale(); <br /> <br /> &lt;/script&gt;<br />raul@webstorm.ro (Raul Molnar)JS/Jqueryhttp://www.w4schools.org/jquery-grayscale-13.htmlMon, 18 Mar 2013 19:02:36 +0200Simple slideshowhttp://www.w4schools.org/simple-slideshow-12.htmlThis is a simple example of a JavaScript slideshow animation effect using JQuery. Simple token string: YP3JJP2EWE53 <br /> &lt;style&gt;<br /> #slideshow img { <br /> opacity:0;<br /> filter:alpha(opacity = 0);<br /> position:absolute;<br /> }<br /> #slideshow img.current { opacity:1;<br /> filter:alpha(opacity = 100); }<br /> &lt;/style&gt;<br /> <br /> &lt;div id=&quot;slideshow&quot;&gt;<br /> &lt;img src=&quot;img/demo/img1.jpg&quot; alt=&quot;image 1&quot; class=&quot;current&quot; /&gt;<br /> &lt;img src=&quot;img/demo/img2.jpg&quot; alt=&quot;image 2&quot; /&gt;<br /> &lt;img src=&quot;img/demo/img3.jpg&quot; alt=&quot;image 3&quot; /&gt;<br /> &lt;/div&gt;<br /> &lt;script type=&quot;text/javascript&quot;&gt;<br /> function shoot(id,interval) {<br /> var slider=$('#'+id);<br /> var current=slider.find('.current');<br /> if (current.is(&quot;:last-child&quot;)) { var next=slider.find('img').first();} <br /> else { var next=current.next('img'); }<br /> current.animate({opacity: 0}, {duration:interval, <br /> step: function(now,fx) {next.css(&quot;opacity&quot;,1-now);}, <br /> complete:function() { current.removeClass(&quot;current&quot;);<br /> current.css(&quot;opacity&quot;,&quot;&quot;); <br /> next.addClass(&quot;current&quot;); <br /> shoot(id,interval); }});<br /> }<br /> <br /> // 3000 (miliseconds) is the timeout between image changes<br /> <br /> shoot(&quot;slideshow&quot;,3000); <br /> <br /> &lt;/script&gt;<br />raul@webstorm.ro (Raul Molnar)JS/Jqueryhttp://www.w4schools.org/simple-slideshow-12.htmlWed, 27 Mar 2013 16:39:49 +0200CSS gray imageshttp://www.w4schools.org/css-gray-images-11.htmlThis example shows how to make a grayscale div, no matter what its content is. For this, you need to use .svg (Scalable Vector Graphics) files located within the CSS style folder. <br /><br /> <b class="red">Attention!</b> <b>For </b><b class="green">Safari</b> <b> &lt; 6 you can use this <a class="lightblue" href="http://www.w4schools.org/jquery-grayscale-13.html">link</a> </b> <br /> <br /> &lt;style&gt;<br /> .grayscale img{<br /> filter: url(css/grayscale.svg#greyscale); <br /> filter: gray;<br /> -webkit-filter: grayscale(100%);<br /> -moz-filter: grayscale(100%);<br /> -ms-filter: grayscale(100%);<br /> -webkit-filter: grayscale(100%);<br /> -o-filter: grayscale(100%);<br /> <br /> }<br /> &lt;/style&gt;<br /> <br /> &lt;div class=&quot;grayscale&quot;&gt;<br /> &lt;p&gt;Grayscale&lt;/p&gt;<br /> &lt;img src=&quot;img/logo.png&quot; alt=&quot;grayscale demo&quot; /&gt;<br /> &lt;/div&gt;<br /> &lt;br /&gt;<br /> &lt;div&gt;<br /> &lt;p&gt;Normal image&lt;/p&gt;<br /> &lt;img src=&quot;img/logo.png&quot; alt=&quot;normal demo&quot; /&gt;<br /> &lt;/div&gt;<br /> Below, is the sample .SVG file used in the demo. For production purposes, please use your own. For your own demo, simply download or copy/ paste the content below to a .svg file placed in the "img" folder. <br /> &lt;svg version=&quot;1.1&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;<br /> &lt;filter id=&quot;greyscale&quot;&gt;<br /> &lt;feColorMatrix type=&quot;matrix&quot; values=&quot;0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0&quot;/&gt;<br /> &lt;/filter&gt;<br /> &lt;/svg&gt;<br /> <br /> The following example is activating the grayscale only for <b>mouse over</b> <br /> &lt;style&gt;<br /> .grayHover:hover img{<br /> filter: url(css/grayscale.svg#greyscale); <br /> -webkit-filter: grayscale(100%);<br /> -moz-filter: grayscale(100%);<br /> -ms-filter: grayscale(100%);<br /> -o-filter: grayscale(100%);<br /> filter: gray;<br /> -webkit-filter: grayscale(1);<br /> }<br /> &lt;/style&gt;<br /> <br /> &lt;div class=&quot;grayHover&quot;&gt;<br /> &lt;p&gt;Grayscale on mouse over&lt;/p&gt;<br /> &lt;img src=&quot;img/logo.png&quot; alt=&quot;grayscale mouse over demo&quot; /&gt;<br /> &lt;/div&gt;<br />raul@webstorm.ro (Raul Molnar)CSS Trickshttp://www.w4schools.org/css-gray-images-11.htmlMon, 18 Mar 2013 19:02:36 +0200CSS resize transitionhttp://www.w4schools.org/css-resize-transition-10.htmlThis simple CSS example shows how to create a resize effect occurring on mouse over. It should work on all browsers, except for IE &lt; 10. <br /> &lt;style&gt;<br /> .demo {width:100px;height:100px;<br /> transition-duration: 1s;transition: height 1s;-moz-transition: height 1s;<br /> -webkit-transition: height 1s; -o-transition: height 1s;<br /> background:#06C;<br /> color:white;<br /> text-align:center;<br /> }<br /> .demo:hover {height:200px; color:#F00;}<br /> &lt;/style&gt;<br /> <br /> &lt;div class=&quot;demo&quot;&gt;Please move the mouse over here&lt;/div&gt;<br /> <br />raul@webstorm.ro (Raul Molnar)CSS Trickshttp://www.w4schools.org/css-resize-transition-10.htmlMon, 18 Mar 2013 19:02:36 +0200Opacity for all browsershttp://www.w4schools.org/opacity-for-all-browsers-9.html<p>This is a simple variable opacity effect (or filter) example using CSS. It should work on all browsers.</p> <br /> &lt;style&gt;<br /> <br /> .squarea {<br /> width:100px; <br /> height:100px; <br /> background:#F00;}<br /> .squareb { <br /> width:100px; <br /> height:100px; <br /> background:#FF0;<br /> top:-50px; <br /> position:relative; <br /> left:50px; opacity:0.5; <br /> filter: alpha(opacity = 50); <br /> }<br /> &lt;/style&gt;<br /> <br /> &lt;div class=&quot;squarea&quot;&gt;&lt;/div&gt;<br /> &lt;div class=&quot;squareb&quot;&gt;&lt;/div&gt;<br />raul@webstorm.ro (Raul Molnar)CSS Trickshttp://www.w4schools.org/opacity-for-all-browsers-9.htmlWed, 27 Mar 2013 16:36:41 +0200Simple Cachehttp://www.w4schools.org/simple-cache-8.htmlThis fairly simple and easy to use PHP class can be used for web page caching purposes. Requirements: <ol> <li>You should <i>have writing permissions/ privileges</i> for the caching folder (eg. <i>chmod 666</i> or <i>777</i>)!</li> <li>You should <i>add some attached value</i> (for example a cookie or a session value) for the logged in users!</li> <li>The caching object should be added right <i>after the initialization of the session cookie</i>!</li> </ol> <p>Cache types table:</p> <table border="1" class="collapsed"> <tr> <td>Type</td><td>Cache action</td> </tr> <tr> <td>0</td><td>No cache</td> </tr> <tr> <td>1</td><td>Server-side cache</td> </tr> <tr> <td>2</td><td>Client-side cache</td> </tr> <tr> <td>3</td><td>Both sides cache</td> </tr> </table> <br /> Usage: <br /> &lt;php&gt;<br /> <br /> $folder=$_SERVER['DOCUMENT_ROOT'].&quot;/cache_&quot;;<br /> $cache=new CACHE($folder);<br /> $cache-&gt;startCache();<br /> <br /> &lt;/php&gt;<br /> <br /> &lt;php&gt;<br /> <br /> $folder=$_SERVER['DOCUMENT_ROOT'].&quot;/cache_&quot;;<br /> $cache=new CACHE($folder);<br /> $cache-&gt;startCache();<br /> <br /> &lt;/php&gt;<br /> <br /> &lt;php&gt;<br /> <br /> //b) Server-side caching<br /> <br /> $folder=$_SERVER['DOCUMENT_ROOT'].&quot;/cache_&quot;;<br /> $cache=new CACHE($folder);<br /> $cache-&gt;setCacheType(1); //Server side caching<br /> $cache-&gt;startCache();<br /> <br /> //c) Client-side (browser) caching<br /> <br /> $folder=$_SERVER['DOCUMENT_ROOT'].&quot;/cache_&quot;;<br /> $cache=new CACHE($folder);<br /> $cache-&gt;setCacheType(2); //Client side caching<br /> $cache-&gt;startCache();<br /> <br /> //d) Both (server and client browser) sides caching<br /> <br /> $folder=$_SERVER['DOCUMENT_ROOT'].&quot;/cache_&quot;;<br /> $cache=new CACHE($folder);<br /> $cache-&gt;setCacheType(3); //Both side caching<br /> $cache-&gt;startCache();<br /> <br /> //e) Simple client-side cache<br /> <br /> $folder=$_SERVER['DOCUMENT_ROOT'].&quot;/cache_&quot;;<br /> $cache=new CACHE($folder,1);<br /> $cache-&gt;startCache();<br /> <br /> //f) Logged in user, both sides cache<br /> <br /> $folder=$_SERVER['DOCUMENT_ROOT'].&quot;/cache_&quot;;<br /> $cache=new CACHE($folder,2, $_COOKIE['user']); // $_COOKIE['user'] is just an example<br /> $cache-&gt;startCache();<br /> <br /> //g) Changing the default settings (in the cache.php file):<br /> <br /> private $root=&quot;&quot;; //Path to the local folder, YOU NEED WRITING PERMISSIONS (chmod 666 or 777)<br /> private $server__cache_time=300; // How long a file will remain cached on the server (seconds)<br /> private $client__cache_time=150; //How long a file will remain cached within the browser (seconds)<br /> private $cache_type=2; // 0 = No cache, 1 = Server-side cache, 2 = Client-side (browser) cache, 3 = Both sides caching<br /> private $attached_value=&quot;&quot;; //Useful for some COOKIE or SESSION values (may be used for logged in users)<br /> private $page;<br /> public $file_name; //The cache file name on server<br /> public $full_file_name; //Full file path and name on the server<br /> public $need_update=false; //If true, then the content will be saved in the path (full_file_name)<br /> public $file_extension=&quot;html&quot;; //Useful for faster checking of the cache contents<br /> <br /> //i) Extra basic usage<br /> $cache=new CACHE($_SERVER['DOCUMENT_ROOT'].&quot;/cache_&quot;,2);<br /> $cache-&gt;startCache();<br /> //Within these lines of code all caching is performed, no matter the page HTML content is loaded afterwards.<br /> <br /> //j) All methods<br /> <br /> $folder=$_SERVER['DOCUMENT_ROOT'].&quot;/cache_&quot;;<br /> $cache=new CACHE();<br /> $cache-&gt;setRoot($folder); //Path where the cached files will be saved<br /> $cache-&gt;setCacheType(3); //Both side caching<br /> $cache-&gt;setClientCacheTime(100); //The page will be kept in user's browser for a maximum of 100 s, the page will be same for this amount<br /> $cache-&gt;setServerCacheTime(300); //The page will be kept on the server for ALL users for a maximum of 300 s, and will not be generated dynamically within that interval<br /> $cache-&gt;setCacheTime(225); //Both caching intervals will be set to 225 seconds, in this case the two previous calls will get overwritten (setClientCacheTime, setServerCacheTime)<br /> $cache-&gt;setFileExtension(&quot;html&quot;); //This will save cached files as HTML/XHTML and it will make it easier to check the cached contents<br /> $cache-&gt;startCache(); //Start caching<br /> &lt;/php&gt;<br /> <p><b>The cache class:</b></p> <br /> &lt;php&gt;<br /> // Created by Raul Molnar (raul@webstorm.ro, for support)<br /> // You have full rights to change, use, sell or donate some amount (to the Paypal account rm@webstorm.ro) .<br /> // Have fun!<br /> <br /> class CACHE {<br /> <br /> <br /> private $root=&quot;&quot;; //Path to the local folder, YOU NEED WRITE PERMISSIONS (chmod 666 or 777)<br /> private $server__cache_time=300; //How long a file will be cached on the server, in seconds<br /> private $client__cache_time=150; //How long will be cached a file on browser in seconds<br /> private $cache_type=2; //0 = No cache, 1 = Server side cache, 2 = Client side (browser) cache, 3 = Both sides cache<br /> private $attached_value=&quot;&quot;; //Useful for COOKIE or SESSION values. May be used for logged in users, for example<br /> private $page;<br /> public $file_name; // The cache file name on server<br /> public $full_file_name; //Full file path and name on the server<br /> public $need_update=false; //If true, the content will be saved locally in the path (full_file_name)<br /> public $file_extension=&quot;html&quot;; //Useful to check the cache content faster<br /> <br /> <br /> public function __construct($root=&quot;&quot;,$cache_type=-1, $attached_value=&quot;&quot;) {<br /> <br /> if ($root!=&quot;&quot;) $this-&gt;setRoot($root);<br /> if ($attached_value!=&quot;&quot;) $this-&gt;attachValue($attached_value);<br /> if ($cache_type!=-1) $this-&gt;setCacheType($cache_type);<br /> <br /> }<br /> <br /> function startCache() { //Start caching <br /> if ($this-&gt;cache_type==1) { <br /> $this-&gt;setServerSideCache();<br /> $this-&gt;setClientCacheTime(0);<br /> }<br /> else if ($this-&gt;cache_type==2) {<br /> $this-&gt;setClientSideCache();<br /> $this-&gt;setServerCacheTime(0);<br /> }<br /> else if ($this-&gt;cache_type==3) {<br /> $this-&gt;setClientSideCache();<br /> $this-&gt;setServerSideCache();<br /> }<br /> else {<br /> $this-&gt;setCacheTime(0);<br /> $this-&gt;setClientSideCache(); <br /> }<br /> <br /> }<br /> <br /> function setRoot($root) { //Sets the root folder, without the ending slash<br /> $this-&gt;root=$root;<br /> }<br /> function setCacheType($cache_type) { //Will set cacheType: 0 = No cache, 1 = Server side cache, 2 = Client side (browser) cache, 3 = Both sides caching<br /> $this-&gt;cache_type=$cache_type;<br /> }<br /> <br /> function setFileExtension($file_extension) { ; //This will set the temporary cache file extension (HTML is recommended)<br /> $this-&gt;file_extension=$file_extension;<br /> }<br /> <br /> function setClientCacheTime($time) { //Sets client cache time (in seconds)<br /> $this-&gt;client__cache_time=$time;<br /> }<br /> <br /> function setServerCacheTime($time) { //Sets server cache time (in seconds)<br /> $this-&gt;server__cache_time=$time;<br /> }<br /> <br /> function setCacheTime($time) { //Sets both, client and server cache time (in seconds)<br /> $this-&gt;setClientCacheTime($time);<br /> $this-&gt;setServerCacheTime($time); <br /> }<br /> <br /> function attachValue($value) { //Attaches a value related to the cache file, example : USER session or USER cookie, or a test value<br /> $this-&gt;attached_value=$value;<br /> }<br /> <br /> function start_file_cache() { //Prepares the system for file caching (server side)<br /> $this-&gt;need_update=true;<br /> ob_start();<br /> }<br /> <br /> function setClientSideCache() { //Sets the necessary headers for client side caching<br /> <br /> <br /> if ($this-&gt;client__cache_time&gt;0) {<br /> <br /> $time_format = gmdate(&quot;D, d M Y H:i:s&quot;, time() + $this-&gt;client__cache_time) . &quot; GMT&quot;;<br /> header(&quot;Expires: &quot;.$time_format);<br /> header(&quot;Pragma: cache&quot;);<br /> header(&quot;Cache-Control: max-age=&quot;.$this-&gt;client__cache_time);}<br /> else { header('Cache-Control: no-cache');<br /> header('Pragma: no-cache'); }<br /> <br /> }<br /> <br /> function setServerSideCache() { //Checking if the file is already there and not expired (in the interval of &quot;server__cache_time&quot; seconds you set<br /> <br /> if ($this-&gt;server__cache_time&amp;lt;=0) return;<br /> <br /> $this-&gt;page=$_SERVER['REQUEST_URI'];<br /> $sanitize=$result = preg_replace(&quot;/[^a-zA-Z0-9]+/&quot;, &quot;&quot;,$_SERVER['PHP_SELF']);<br /> $this-&gt;file_name=$sanitize.&quot;-&quot;.substr(md5($this-&gt;page),10,16); //Generates a file name, you can put any rule here<br /> <br /> if (strlen($this-&gt;attached_value)&gt;0) { $this-&gt;file_name.=&quot;-&quot;.$this-&gt;attached_value; }<br /> if (strlen($this-&gt;file_extension)&gt;0) { $this-&gt;file_name.=&quot;.&quot;.$this-&gt;file_extension; }<br /> <br /> $this-&gt;full_file_name=$this-&gt;root.&quot;/&quot;.$this-&gt;file_name;<br /> <br /> if (file_exists($this-&gt;full_file_name)) {<br /> $file_time=filemtime($this-&gt;full_file_name);<br /> $now_time=time(false);<br /> <br /> if (($file_time-$now_time)&gt;=$this-&gt;server__cache_time) { $this-&gt;start_file_cache(); } //If the cache file is expired, will get replaced by a more recent one<br /> else {<br /> @readfile($this-&gt;full_file_name);<br /> die(&quot;&quot;); //If the cache file is not expired, it will only display the content and the script will stop<br /> }<br /> } else {<br /> $this-&gt;start_cache(); //If the cache file is not created, we will simply create it<br /> }<br /> <br /> }<br /> <br /> function callback($buffer) {<br /> return $buffer.$this-&gt;save_file($buffer);<br /> } <br /> <br /> function save_file($content) { //This will save the cache file, fopen (or any method, even a database query) can be used for writing<br /> <br /> if ($file = @fopen($this-&gt;full_file_name, &quot;wb&quot;))<br /> {<br /> @fwrite($file, $content);<br /> @fclose($file);<br /> } <br /> return &quot;&quot;;<br /> }<br /> <br /> function start_cache() {<br /> $this-&gt;need_update=true;<br /> ob_start(array(&amp;amp;$this, 'callback'));<br /> }<br /> }<br /> &lt;/php&gt;<br />raul@webstorm.ro (Raul Molnar)PHPhttp://www.w4schools.org/simple-cache-8.htmlMon, 18 Mar 2013 19:02:36 +0200Paypal without formhttp://www.w4schools.org/paypal-without-form-6.html<p>This class allows for one's basic usage of PayPal's services. Easy to use, easy to customize, this code allows for the minimum number of clicks.</p> <p>Its usage requires one to import the PHP class where needed, and then instantiate its objects like below.</p> <p>Usage:</p> <br /> &lt;php&gt;<br /> $paypal=new PAYPAL(&quot;rm@webstorm.ro&quot;);<br /> $paypal-&gt;addItem(&quot;Super Socks Test&quot;,&quot;10&quot;,0);<br /> $paypal-&gt;pay();<br /> &lt;/php&gt;<br /> Below it's the same code with full class source code included (imported) + testing demo. <b>Please do not try to send money to the demo account. Thank you!</b> <br /> &lt;php&gt; <br /> <br /> // This is the class that gets the job done<br /> // Do not alter, unless you know what you are doing.<br /> <br /> class PAYPAL {<br /> <br /> public $currency_code=&quot;USD&quot;; //you can change with any<br /> public $email=&quot;your email here&quot;; //the recipient email<br /> private $callback_url=&quot;&quot;; //your callback url here<br /> public $paypal_host=&quot;https://www.paypal.com/cgi-bin/webscr&quot;;<br /> public $items=array();<br /> private $payment_data=array();<br /> <br /> public function __construct($email=NULL) {<br /> if (strlen($email)&gt;0) $this-&gt;email=$email;<br /> }<br /> <br /> function getData() {<br /> <br /> $standard_values=array( <br /> &quot;currency_code&quot;=&gt;$this-&gt;currency_code,<br /> &quot;cmd&quot; =&gt; &quot;_cart&quot;,<br /> &quot;upload&quot; =&gt; &quot;1&quot;,<br /> &quot;business&quot; =&gt; $this-&gt;email,<br /> &quot;callback_version&quot; =&gt; 61,<br /> &quot;callback_timeout&quot; =&gt;3,<br /> &quot;fallback_shipping_option_name_0&quot; =&gt; &quot;Option 1&quot;,<br /> &quot;fallback_shipping_option_amount_0&quot; =&gt; 0,<br /> &quot;fallback_shipping_option_is_default_0&quot; =&gt; 1,<br /> &quot;callback_url&quot; =&gt; urlencode($this-&gt;callback_url),<br /> &quot;notify_url&quot; =&gt; urlencode($this-&gt;callback_url),<br /> &quot;cancel_return&quot; =&gt; urlencode($GLOBALS['srv'])<br /> ); <br /> <br /> $this-&gt;payment_data=$standard_values; <br /> <br /> if (sizeof($this-&gt;items)&gt;0) {<br /> <br /> $itemIndex=1;<br /> foreach($this-&gt;items as $item) {<br /> $this-&gt;payment_data['item_name_'.$itemIndex]=$item['name'];<br /> $this-&gt;payment_data['amount_'.$itemIndex]=$item['price'];<br /> $this-&gt;payment_data['shipping_'.$itemIndex]=$item['shipping'];<br /> $itemIndex+=1;}<br /> }<br /> <br /> <br /> }<br /> <br /> function addItem($name,$price,$shipping) {<br /> if ((strlen($name)&gt;1) &amp;amp;&amp;amp; ($price&gt;0))<br /> $this-&gt;items[]=array(<br /> &quot;name&quot; =&gt; $name,<br /> &quot;price&quot; =&gt; number_format($price,2),<br /> &quot;shipping&quot; =&gt; $shipping<br /> );<br /> }<br /> <br /> function pay() {<br /> <br /> if (sizeof($this-&gt;items)==0) return;<br /> $this-&gt;getData();<br /> echo $this-&gt;paypal_host.&quot;?&quot;.http_build_query($this-&gt;payment_data);<br /> header(&quot;Location: &quot;.$this-&gt;paypal_host.&quot;?&quot;.http_build_query($this-&gt;payment_data));<br /> die(&quot;&quot;);<br /> }<br /> }<br /> <br /> // Basic Usage<br /> // Please DO EDIT the three lines below, to suit your needs.<br /> // Please notice how the example below has two items<br /> $paypal=new PAYPAL(&quot;rm@webstorm.ro&quot;);<br /> $paypal-&gt;addItem(&quot;Super Socks Test&quot;,&quot;10&quot;,0);<br /> $paypal-&gt;addItem(&quot;Super Socks 2&quot;,&quot;20&quot;,0);<br /> $paypal-&gt;pay();<br /> <br /> &lt;/php&gt;<br /> <b>Clicking the DEMO button produces the same result as clicking on some instantiated link. You can safely close that window after analyzing its content.</b>raul@webstorm.ro (Raul Molnar)PHPhttp://www.w4schools.org/paypal-without-form-6.htmlMon, 18 Mar 2013 19:02:36 +0200Replace the last string occurencehttp://www.w4schools.org/replace-the-last-string-occurence-5.htmlThis function replaces the last string occurrence in a given text with the specified string. This is may be an alternative for preg_replace() function <br /> &lt;php&gt;<br /> <br /> function str_replace_last($string ,$search , $replace){<br /> <br /> if ((($string_len=strlen($string))==0) || (($search_len=strlen($search))==0)) return $string;<br /> $pos=strrpos($string,$search);<br /> if ($pos&gt;0) return substr($string,0,$pos).$replace.substr($string,$pos+$search_len,max(0,$string_len-($pos+$search_len)));<br /> return $string;<br /> } <br /> <br /> //Usage example<br /> <br /> $text=&quot;I love apples. I love bananas.&quot;;<br /> echo str_replace_last($text,&quot;love&quot; , &quot;don't love&quot;);<br /> <br /> //The result: <br /> //I love apples. I don't love bananas.<br /> &lt;/php&gt;<br />raul@webstorm.ro (Raul Molnar)PHPhttp://www.w4schools.org/replace-the-last-string-occurence-5.htmlMon, 18 Mar 2013 19:02:36 +0200Replace only the first string occurencehttp://www.w4schools.org/replace-only-the-first-string-occurence-4.htmlThis PHP functon will replace <b>only</b> the first string occurrence in a given text. This is an alternative for the <i>preg_replace()</i> function. <br /> &lt;php&gt;<br /> <br /> function str_replace_first($string ,$search , $replace) {<br /> <br /> if ((($string_len=strlen($string))==0) || (($search_len=strlen($search))==0)) return $string;<br /> $pos=strpos($string,$search);<br /> if ($pos&gt;0) return substr($string,0,$pos).$replace.substr($string,$pos+$search_len,max(0,$string_len-($pos+$search_len)));<br /> return $string;<br /> } <br /> <br /> //Usage example<br /> <br /> $text=&quot;I love apples. I love bananas.&quot;;<br /> echo str_replace_first($text,&quot;love&quot;,&quot;don't love&quot;);<br /> <br /> //The result <br /> //I don't love apples. I love bananas.<br /> <br /> &lt;/php&gt;<br />raul@webstorm.ro (Raul Molnar)PHPhttp://www.w4schools.org/replace-only-the-first-string-occurence-4.htmlMon, 18 Mar 2013 19:02:36 +0200Verify emailhttp://www.w4schools.org/verify-email-3.htmlWith this function you can verify whether or not an email address supplied by the user may be a valid email address. Please note that this code is also verifying the domain has at least one MX record, such that it can actually route e-mails. <br /> &lt;php&gt;<br /> function email_for_real($email) {<br /> $details = explode(&quot;@&quot;, $email);<br /> $domain=$details[1];<br /> if (@checkdnsrr($domain, &quot;MX&quot;)) { return true; }<br /> else { return false;}<br /> }<br /> <br /> function good_mail($email) {<br /> if(filter_var($email, FILTER_VALIDATE_EMAIL, true)) <br /> if (email_for_real($email)) return true; <br /> return false; <br /> }<br /> <br /> $email=&quot;test@example.com&quot;;<br /> <br /> if (good_mail($email)) { echo(&quot;The email is good&quot;);} <br /> else { echo( &quot;The email is bad&quot; ); }<br /> &lt;/php&gt;<br />raul@webstorm.ro (Raul Molnar)PHPhttp://www.w4schools.org/verify-email-3.htmlMon, 18 Mar 2013 19:02:36 +0200