Showing posts with label HTML. Show all posts
Showing posts with label HTML. Show all posts

Tuesday, June 12, 2018

Html Simple Tooltip

i have referred the simple tooltip, that is how can we used in our site. 

HTML :

<p data-tip="This is the text of the tooltip">This is a paragraph of text that has a tooltip.</p>

<div data-tip="This is the text of the tooltip2">
    <input type="text" name="test" value="44"/>
</div>

CSS:

[data-tip] {
    position:relative;
}

[data-tip]:before {
    content:'';
    /* hides the tooltip when not hovered */
    display:none;
    content:'';
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid #1a1a1a;  
    position:absolute;
    top:30px;
    left:35px;
    z-index:8;
    font-size:0;
    line-height:0;
    width:0;
    height:0;
}

[data-tip]:after {
    display:none;
    content:attr(data-tip);
    position:absolute;
    top:35px;
    left:0px;
    padding:5px 8px;
    background:#1a1a1a;
    color:#fff;
    z-index:9;
    font-size: 0.75em;
    height:18px;
    line-height:18px;
    -webkit-border-radius: 3px;
    -moz-border-radius: 3px;
    border-radius: 3px;
    white-space:nowrap;
    word-wrap:normal;
}

[data-tip]:hover:before,
[data-tip]:hover:after {
    display:block;
}

Fiddle : http://jsfiddle.net/ch0b7x6a/

Thursday, July 30, 2015

Multiply two values without clicking a button - Jquery

Multiplies both the text input numbers and shows the result in the third box .
User can enter a value in the 2nd text box so it automatically multiplies and shows the result in the 3rd textbox without any button.

HTML CODE:

<input type="text" name="input1" id="input1" value="5">
<input type="text" name="input2" id="input2" value="">
<input type="text" name="output" id="output" value="">

Script:
<script>
$(function(){
   $("#input2,#input1").keyup(function () {

    $('#output').val($('#input1').val() * $('#input2').val());

  });
}); 
</script>

OUTPUT:

http://jsfiddle.net/sarathsprakash/YFgkB/10/


Friday, May 15, 2015

simple jquery tab

Here the tutorial to learn how to make simple jQuery Tabs using CSS & jQuery. 

Step 1:


<head>
<title>Simple Tab with CSS and jQuery </title>
<link rel="stylesheet" href="style.css">
<script src="http://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
    $(".tabs-attempt a").click(function(event) {
        event.preventDefault();
        $(this).parent().addClass("current");
        $(this).parent().siblings().removeClass("current");
        var tab = $(this).attr("href");
        $(".tab-content").not(tab).css("display", "none");
        $(tab).fadeIn();
    });
});
</script>
</head>

style.css

#tabs-container {
  width : 500px;
}
.tabs-attempt {
    height: 15px;
    float: left;
    clear: both;
    list-style: none;
}
.tabs-attempt li {
    height: 30px;
    line-height: 30px;
    float: left;
    margin-right: 10px;
    background-color: #28AADC;
    border-top: 1px solid #d4d4d1;
    border-right: 1px solid #d4d4d1;
    border-left: 1px solid #d4d4d1;
}
.tabs-attempt li.current {
    position: relative;
    background-color: #fff;
    border-bottom: 1px solid #fff;
    z-index: 5;
}
.tabs-attempt li a {
    padding: 10px;
    text-transform: uppercase;
    color: #fff;
    text-decoration: none;
}
.tabs-attempt .current a {
    color: #2e7da3;
}
.tab {
    border: 1px solid #d4d4d1;
    background-color: #fff;
    float: left;
    margin-bottom: 20px;
    width: 500px;
}
.tab-content {
    padding: 20px;
    display: none;
}
#tab-1 {
    display: block;
}

Step 2:

Html view.

<body>
<div id="tabs-container">
    <ul class="tabs-attempt">
        <li class="current"><a href="#tab-1">Tab 1</a></li>
        <li><a href="#tab-2">Tab 2</a></li>
        <li><a href="#tab-3">Tab 3</a></li>
        <li><a href="#tab-4">Tab 4</a></li>
    </ul>
    <div class="tab">
        <div id="tab-1" class="tab-content">
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sit amet purus urna. Proin dictum fringilla enim, sit amet suscipit dolor dictum in. Maecenas porttitor, est et malesuada congue, ligula elit fermentum massa, sit amet porta odio est at velit. Sed nec turpis neque. Fusce at mi felis, sed interdum tortor. Nullam pretium, est at congue mattis, nibh eros pharetra lectus, nec posuere libero dui consectetur arcu. Quisque convallis facilisis fermentum. Nam tincidunt, diam nec dictum mattis, nunc dolor ultrices ipsum, in mattis justo turpis nec ligula. Curabitur a ante mauris. Integer placerat imperdiet diam, facilisis pretium elit mollis pretium. Sed lobortis, eros non egestas suscipit, dui dui euismod enim, ac ultricies arcu risus at tellus. Donec imperdiet congue ligula, quis vulputate mauris ultrices non. Aliquam rhoncus, arcu a bibendum congue, augue risus tincidunt massa, vel vehicula diam dolor eget felis.</p>
        </div>
        <div id="tab-2" class="tab-content">
            <p>Donec semper dictum sem, quis pretium sem malesuada non. Proin venenatis orci vel nisl porta sollicitudin. Pellentesque sit amet massa et orci malesuada facilisis vel vel lectus. Etiam tristique volutpat auctor. Morbi nec massa eget sem ultricies fermentum id ut ligula. Praesent aliquet adipiscing dictum. Suspendisse dignissim dui tortor. Integer faucibus interdum justo, mattis commodo elit tempor id. Quisque ut orci orci, sit amet mattis nulla. Suspendisse quam diam, feugiat at ullamcorper eget, sagittis sed eros. Proin tortor tellus, pulvinar at imperdiet in, egestas sed nisl. Aenean tempor neque ut felis dignissim ac congue felis viverra. </p>
        
        </div>
        <div id="tab-3" class="tab-content">
            <p>Duis egestas fermentum ipsum et commodo. Proin bibendum consectetur elit, hendrerit porta mi dictum eu. Vestibulum adipiscing euismod laoreet. Vivamus lobortis tortor a odio consectetur pulvinar. Proin blandit ornare eros dictum fermentum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur laoreet, ante aliquet molestie laoreet, lectus odio fringilla purus, id porttitor erat velit vitae mi. Nullam posuere nunc ut justo sollicitudin interdum. Donec suscipit eros nec leo condimentum fermentum. Nunc quis libero massa. Integer tempus laoreet lectus id interdum. Integer facilisis egestas dui at convallis. Praesent elementum nisl et erat iaculis a blandit ligula mollis. Vestibulum vitae risus dui, nec sagittis arcu. Nullam tortor enim, placerat quis eleifend in, viverra ac lacus. Ut aliquam sapien ut metus hendrerit auctor dapibus justo porta. </p>
        </div>
        <div id="tab-4" class="tab-content">
            <p>Proin sollicitudin tincidunt quam, in egestas dui tincidunt non. Maecenas tempus condimentum mi, sed convallis tortor iaculis eu. Cras dui dui, tempor quis tempor vitae, ullamcorper in justo. Integer et lorem diam. Quisque consequat lectus eget urna molestie pharetra. Cras risus lectus, lobortis sit amet imperdiet sit amet, eleifend a erat. Suspendisse vel luctus lectus. Sed ac arcu nisi, sit amet ornare tellus. Pellentesque nec augue a nibh pharetra scelerisque quis sit amet felis. Nullam at enim at lacus pretium iaculis sit amet vel nunc. Praesent sapien felis, tincidunt vitae blandit ut, mattis at diam. Suspendisse ac sapien eget eros venenatis tempor quis id odio. Donec lacus leo, tincidunt eget molestie at, pharetra cursus odio. </p>
        </div>
    </div>
</div>
</body>


OUTPUT :

            

Friday, March 27, 2015

jquery - move select box items with groups from one list to another

In the page has two MultiSelect List box with , some items in one box and another one is empty. Able to move items between the two multiselect boxes. We should be even able to move multiple items with group. Here the following example.

<table cellspacing="10" cellpadding="10" border="0">
<tr>
    <td>
        <select multiple id="select1" class="w100p" size="20" maxlength="100">              
            <optgroup label="Group 1">
                <option value="1">Option 1a</option>
                <option value="2">Option 1b</option>
                <option value="2">Option 1c</option>
                <option value="2">Option 1d</option>
                <option value="2">Option 1e</option>
                <option value="2">Option 1f</option>
            </optgroup>
            <optgroup label="Group 2">
                <option value="3">Option 2a</option>
                <option value="4">Option 2b</option>
                <option value="4">Option 2c</option>
                <option value="4">Option 2d</option>
                <option value="4">Option 2e</option>
                <option value="4">Option 2f</option>
                <option value="4">Option 2g</option>
                <option value="4">Option 2h</option>
            </optgroup>
        </select>
    </td>
    <td>
        <a href="#" id="add">add >></a>
        <br>
        <a href="#" id="remove"><< remove</a>
    </td>
    <td>
        <select multiple id="select2" class="w100p" size="20" maxlength="100"></select>
    </td>
</tr>
</table>

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script "text/javascript">
var $select1 = $('#select1');
    var $select2 = $('#select2');

    $([$select1, $select2]).each(function(){
        $(this).find('optgroup').each(function(idx){
            var ogId = 'og' + idx;
            $(this).attr('id', ogId);
            $(this).find('option').each(function(){
                $(this).data('parent', ogId);
            });
        });
    });

    $('#add').click(function() {
        processOptions($select1, $select2);
    });
    $('#remove').click(function() {
        processOptions($select2, $select1);
    });

    var optgFoundInTarget = {};

    function processOptions(source, target) {
        var selectedOptions = $(source).find('option:selected');
        if (selectedOptions.length) {
            selectedOptions.each(function(){
                var movingFromOptGroup = $(this).parent();
                parentOg = $(movingFromOptGroup).attr('id');
                if (parentOg.indexOf('_target') > -1) {
                    parentOg = parentOg.replace('_target', '');
                } else {
                    parentOg += '_target';
                }
                if (typeof optgFoundInTarget[parentOg] == 'object') {
                } else {
                    if (target.find('optgroup#'+parentOg).length) {
                        _el = target.find('optgroup#'+parentOg);
                    } else {
                        _el = $('<optgroup id="' + $(movingFromOptGroup).attr('id') + '_target" label="' + $(movingFromOptGroup).attr('label') + '" />').appendTo(target);
                    }
                    optgFoundInTarget[parentOg] = _el;
                }
                targetOptGroup = optgFoundInTarget[parentOg];
                $(this).data('parent', $(targetOptGroup).attr('id')).appendTo(targetOptGroup);
            });
            $([source, target]).each(function(){
                $(this).find('optgroup').each(function(){
                    $(this).css('display', $(this).find('option').length ? 'inline' : 'none');
                })
            });
            target.val(null);
        }
    }
</script>

OUTPUT:

                 

Jquery - move select box items from one list to another

In the page has two MultiSelect List elements with some items in them. Able to move items between the two multiselect boxes. We should be even able to move multiple items or all items at once. Here the following example.

Example:

 <select id="sbOne" multiple="multiple" size="20" maxlength="100">
        <option value="1">Alpha</option>
        <option value="2">Beta</option>
        <option value="3">Gamma</option>
        <option value="4">Delta</option>
        <option value="5">Epsilon</option>
 </select>
 <select id="sbTwo" multiple="multiple" size="20" maxlength="100">
        <option value="6">Zeta</option>
        <option value="7">Eta</option>
    </select>
    <br />
    <input type="button" id="left" value="<" />
    <input type="button" id="right" value=">" />
    <input type="button" id="leftall" value="<<" />
    <input type="button" id="rightall" value=">>" />

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script  type="text/javascript">
function moveItems(origin, dest) {
    $(origin).find(':selected').appendTo(dest);
}

function moveAllItems(origin, dest) {
    $(origin).children().appendTo(dest);
}

$('#left').click(function () {
    moveItems('#sbTwo', '#sbOne');
});

$('#right').on('click', function () {
    moveItems('#sbOne', '#sbTwo');
});

$('#leftall').on('click', function () {
    moveAllItems('#sbTwo', '#sbOne');
});

$('#rightall').on('click', function () {
    moveAllItems('#sbOne', '#sbTwo');
});
</script>

DEMO : http://www.jquerycookbook.com/demos/S4-DropDownULLists/43-MoveMultiSelectListItems.html




Jquery - horizontal scroll bar in select box

Trying to add horizontal scroll bar in select box. Its very simple. Here follow the code and see the example.

<div id='Courselists' style="overflow-x:scroll; width:200px; overflow: -moz-scrollbars-horizontal;">
<select id='Courses' name="mySelect" size="15">
    <option value="5">Ajax</option>
    <option value="9">Animal</option>
    <option value="6">HETC course1</option>
    <option value="10">HTML</option>
    <option value="3">Java</option>
    <option value="4">mysql</option>
    <option value="11">Photoshop</option>
    <option value="2">PHP</option>
    <option value="8">Science</option>
    <option value="7">Test course: XS</option>
    <option value="12">Test test Test test Test test Test test Test test </option>
</select>
<div id="Scrolldiv" style='font-size: 1px'>&nbsp</div>
</div>

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    $('#Scrolldiv').css('width', $('#Courses').outerWidth());
    $('#Courses').css('width', $('#Courselists').outerWidth());
    $( "#Courselists" ).scroll(function() {
        $('#Courses').css('width', $(this).outerWidth() + $(this).scrollLeft());
    });
</script>

OUTPUT:
                 


Special thanks to Cyrus . 

Friday, December 07, 2012

Scroll loading content with ajax

Today we learn about some thing in Ajax in jquery.First i said  thanks for the code.And i got this code from google and share with all.Its really helpful for us. How can the content loading from scroll using  ajax method.This is easiest way to learn it.simply few steps to follow. And this is one type of pagination too.

Step 1:
<script type="text/javascript" src="http://www:yoursite.com/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="http://www:yoursite.com/js/scroll.js"></script>
    <script type="text/javascript">
      // var mtu4 = jQuery.noConflict();
      //  mtu4(function($){                   
            $('#archive1').scrollLoad({               
                    url : 'http://www.yoursite.com/getarchive1_infos.php', //your ajax file to be loaded when scroll breaks ScrollAfterHeight
            getData : function()
                           {
                    // you can post some data along with ajax request  return {offset:rel_data,userName:'Web Developer'};   
                      var rel_data = $("#infinite_scroll").attr("rel");
                      rel_data = parseInt(rel_data);                       
                      rel_data = rel_data+15;
                      $("#infinite_scroll").attr("rel",rel_data);
                      return {offset:rel_data};                           
                },
                start : function() {
                    $('<div class="loading" style="padding:10px 0; margin:0 37.7%;"><p style=" font-size: 14px;font-weight: bold;line-height: 25px;">Loading...</p><img src="http://www.yoursite.com/images/uploading.gif"/></div>').appendTo(this);
                    // you can add your effect before loading data
                },
       ScrollAfterHeight : 95, //this is the height in percentage after which ajax stars
                onload : function( data ) {
                                        $(this).append( data );
                                        $('.loading').remove();
                }, // this event fires on ajax success

                continueWhile : function( resp ) {
                    if( $(this).children('li').length >= 100 ) { // stops when number of 'li' reaches 100
                        return false;
                    }
                    return true;
                }
            });    
                //});    
        </script>       

Step 2:       
Following content html first loading with 15 records in landing page.Once the end of the scroll another 15 records will loading from ajax file (getarchive1_infos.php).

       <div class="chart_table1" id="archive1">
             <div id="infinite_scroll"  class="scroll" rel="0">
           <?php for ($i=1; $i<=15; $i++){    ?>
                   <p>hi this is sample test</p>
          <?php } ?>
           </div>
      </div>

Step 3:                       
This is getarchive1_infos.php ajax file.Another 15 records are loading.  
      <?php
                    $offset = $_REQUEST['offset'];
               for ($i=1; $i<=$offset; $i++){    ?>
                   <p>hi this is sample test from ajax</p>
                    <?php } ?>
         
step 4:
    And this is scroll.js script file.      
    <script type="application/javascript">
        ( function( $ ) {
    $.fn.scrollLoad = function( options ) {
   
        var defaults = {
            url : '',
            data : '',
            ScrollAfterHeight : 90,
            onload : function( data, itsMe ) {
                alert( data );
            },
            start : function( itsMe ){},
            continueWhile : function() {
                return true;
            },
            getData : function( itsMe ) {
                return '';
            }
        };

        for( var eachProperty in defaults ) {
            if( options[ eachProperty ] ) {
                defaults[ eachProperty ] = options[ eachProperty ];
            }
        }

        return this.each( function() {
            this.scrolling = false;
            this.scrollPrev = this.onscroll ? this.onscroll : null;
            $( this ).bind( 'scroll', function ( e ) {
                if( this.scrollPrev ) {
                    this.scrollPrev();
                }
                if( this.scrolling ) return;
                //var totalPixels = $( this ).attr( 'scrollHeight' ) - $( this ).attr( 'clientHeight' );
                if( Math.round( $( this ).attr( 'scrollTop' ) / ( $( this ).attr( 'scrollHeight' ) - $( this ).attr( 'clientHeight' ) ) * 100 ) > defaults.ScrollAfterHeight ) {
                    defaults.start.call( this, this );
                    this.scrolling = true;
                    $this = $( this );
                    $.ajax( { url : defaults.url, data : defaults.getData.call( this, this ), type : 'post', success : function( data ) {
                        $this[ 0 ].scrolling = false;
                        defaults.onload.call( $this[ 0 ], data, $this[ 0 ] );
                        if( !defaults.continueWhile.call( $this[ 0 ], data ) ) {
                            $this.unbind( 'scroll' );
                        }
                    }});
                }
            });
        });
    }
})( jQuery );
</script> 


Finally we learn about this , how can scroll the content loading from ajax.
cheers friends!!! :)
   

Thursday, August 16, 2012

Get all the top google search results | google ajax api

We will be using the google ajax api in this script. As you might have found, by default it gives out only 4 results. Or you may manage to get 8 with one more parameter. But here, with some tweaks, you will get the top 64 results! (And 64 is the upper limit, because google doesn’t like bots.)

<?php
function google_search_api($args, $referer = 'http://localhost/testing/', $endpoint = 'web')
{
 
if ( !array_key_exists('v', $args) )
$args['v'] = '1.0';
//$args['key']="ABQIAAAArMTuM-CBxyWL0PYBLc7SuhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxT-uD75NXlWUsDRBw-8aVAlQ29oCg";
//$args['userip']=$_SERVER['REMOTE_ADDR'];
$args['rsz']='8';
$url .= '?'.http_build_query($args, '', '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// note that the referer *must* be set
curl_setopt($ch, CURLOPT_REFERER, $referer);
$body = curl_exec($ch);
curl_close($ch);
//decode and return the response
return json_decode($body,true);
}
$query=urldecode(isset($_GET['q'])?$_GET['q']:"none");
echo "Results for: $query<br />-----<br />";
$res = google_search_api(array('q' => $query));
$pages=$res['responseData']['cursor']['pages'];
$nres=0;
for($i=0;$i<count($pages);$i++)
{
$res = google_search_api(array('q' => $query,'start'=>$rez['responseData']['cursor']['pages'][$i]['start']));
for($j=0;$j<count($res['responseData']['results']); $j++)
{
$nres++;
echo urldecode($res['responseData']['results'][$j]['url'])."<br />";
}
}
echo "<br />---<br />Total number of reuslts: $nres";
?>
 

Friday, August 10, 2012

10 Reasons To Choose Drupal Over Joomla

1. SEO Friendly URL’s – This is a pain in the butt with Joomla! It’s automatically built in with Drupal and very very easy to use.
   2. Easy To Use Admin Interface - I think Joomla tried a little too hard in this area. Drupal found a way to just make things more simple and not so overwhelming for the beginner user.
   3. Built In Blog – The blog that’s built in to Drupal is very easy to use and customize. Joomla really does not give a good blogging option at all surprisingly.
   4. Web Forms Plugin – This is a terrific plugin that I suggest you use. Just do a search for it on the Drupal.org website. Let’s you create as many of your own customized forms as you need. Very easy to use and very comprehensive.
   5. User Management – User roles and access control is so much easier to manage and maintain using Drupal. It makes multi-user websites easy to create rather than a pain in the neck.
   6. Ubercart – I just recently wrote about this shopping cart plugin for Drupal. Hands down the best shopping cart you will find for any content management system period.
   7. Drupal Taxonomy – Drupal’s way of categorizing content is such much better than Joomla. You can tell that it was way more thought out beforehand. This is important for anyone creating content rich websites.
   8. Meta Tags Plugin - a fantastic plugin allowing you to create custom meta keywords and more importantly descriptions for each page. Do a search for this one. Great Plugin.
   9. Page Title Plugin – Something Joomla does not currently have. A plugin that EASILY allows you to customize each pages Page Title. An absolute must for search engine optimization.
  10. Social Networking – For a major social network I of course choose elgg. However, if you are looking to build a more niche/smaller social network than Drupal is perfect. Again referencing to it’s user management capabilities combined with it’s Drupal Taxonomy to content manage all content Drupal makes for a fantastic easy to setup social network.

I wrote this post for two major reasons. First and foremost of course, to inform you the reader about Drupal and it’s advantages. The other is to hopefully in one way or the other encourage Joomla to “take it to another level” if you will. Hopefully it will help motivate Joomla contributors and creators to better refine the CMS that they have. If they don’t, people are gonna find out how much better Drupal is and stick with them.

jquery | show and hide div contents

sample coding

inside java script

$(document).ready(function(){
$("#Advancedsettings").hide();
$("#Basicsettings").hide();
$("#BS").click(function(event){
event.preventDefault();
$("#Basicsettings").show();
$("#Advancedsettings").hide();

});
$("#AS").click(function(event){
event.preventDefault();
$("#Basicsettings").hide();
$("#Advancedsettings").show();

});

});

40 Tips for optimizing your php code

1. If a method can be static, declare it static. Speed improvement is by a factor of 4.
2. echo is faster than print.
3. Use echo’s multiple parameters instead of string concatenation.
4. Set the maxvalue for your for-loops before and not in the loop.
5. Unset your variables to free memory, especially large arrays.
6. Avoid magic like __get, __set, __autoload
7. require_once() is expensive
8. Use full paths in includes and requires, less time spent on resolving the OS paths.
9. If you need to find out the time when the script started executing, $_SERVER[’REQUEST_TIME’] is preferred to time()
10. See if you can use strncasecmp, strpbrk and stripos instead of regex
11. str_replace is faster than preg_replace, but strtr is faster than str_replace by a factor of 4
12. 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.
13. It’s better to use switch statements than multi if, else if, statements.
14. Error suppression with @ is very slow.
15. Turn on apache’s mod_deflate
16. Close your database connections when you’re done with them
17. $row[’id’] is 7 times faster than $row[id]
18. Error messages are expensive
19. Do not use functions inside of for loop, such as for ($x=0; $x < count($array); $x) The count() function gets called each time. 20. Incrementing a local variable in a method is the fastest. Nearly the same as calling a local variable in a function. 21. Incrementing a global variable is 2 times slow than a local var. 22. Incrementing an object property (eg. $this->prop++) is 3 times slower than a local variable.
23. Incrementing an undefined local variable is 9-10 times slower than a pre-initialized one.
24. 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.
25. 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.
26. Methods in derived classes run faster than ones defined in the base class.
27. 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.
28. 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.
29. When echoing strings it’s faster to separate them by comma instead of dot. Note: This only works with echo, which is a function that can take several strings as arguments.
30. 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.
31. 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.
32. 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
33. When working with strings and you need to check that the string is either of a certain length you’d understandably would want to use the strlen() function. This function is pretty quick since it’s operation does not perform any calculation but merely return the already known length of a string available in the zval structure (internal C struct used to store variables in PHP). However because strlen() is a function it is still somewhat slow because the function call requires several operations such as lowercase & hashtable lookup followed by the execution of said function. In some instance you can improve the speed of your code by using an isset() trick.Ex.if (strlen($foo) < 5) { echo “Foo is too short”; }vs.

if (!isset($foo{5})) { echo “Foo is too short”; }

Calling isset() happens to be faster then strlen() because unlike strlen(), isset() is a language construct and not a function meaning that it’s execution does not require function lookups and lowercase. This means you have virtually no overhead on top of the actual code that determines the string’s length.
34. 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.
35. Not everything has to be OOP, often it is too much overhead, each method and object call consumes a lot of memory.
36. Do not implement every data structure as a class, arrays are useful, too
37. Don’t split methods too much, think, which code you will really re-use
38. You can always split the code of a method later, when needed
39. Make use of the countless predefined functions
40. If you have very time consuming functions in your code, consider writing them as C extensions