Tag Archives: php - Page 2

array_change_key_case ( ) – Change array keys or index to uppercase or lowercase

The PHP array function array_change_key_case ( ) will change the key of an array to either lower case or upper case depending upon the parameter specified.The PHP array function array_change_key_case ( )  accepts two parameter.

  1. An array
  2. The CASE

The first parameter we feed this function is the target array. The second parameter allows you to specify either CASE_LOWER or CASE_UPPER. If you do not specify a second parameter this function will default to using CASE_LOWER to change the case of all keys in the array.

SYNTAX:

array_change_key_case(array,case)

EXAMPLE OF PHP array function array_change_key_case ( ) :

<?php
    $info=array("name"=>"amit","age"=>"22","address"=>"Nepal");
    $info = array_change_key_case($myCarInfo, CASE_UPPER);
    foreach ($info as $key => $value) {
        echo "$key | $value <br />"; 
    }
?>

Output:

NAME | amit
AGE | 22
ADDRESS | Nepal

Similar Example:

How to generate unique ID in php

Many developers use md5 or rand() function to generate the unique id in php, Which is actually not a good practice under some senario. The best technique is to use the pre given php function whic is uniqid()

Example:

 

    // generate unique string
    echo uniqid();
    /* prints
    4bd67c947233e
    */  

    // generate another unique string
    echo uniqid();
    /* prints
    4bd67c9472340
    */
    // with prefix
    echo uniqid('ilovephp_');
    /* prints
    ilovephp_4bd67d6cd8b8f
    */  

    // with more entropy
    echo uniqid('',true);
    /* prints
    4bd67d6cd8b926.12135106
    */  

    // both
    echo uniqid('phpfresher_',true);
    /* prints
    phpfresher_4bd67da367b650.43684647
    */

Related Links for PHP

Link one

Link Two

Link Three

height:auto not working

I have been facing with css problem from long time, that i have three divs

  • container
  • leftbar
  • rightbar
    .container{
          height: auto;
         ....
         ...
 }
.leftbar{
          float:left;
         ....
         ...
 }
.rightbar{
        float:right;
.....
}

The problem i am facing is, when the rightbar div or the leftbar div height increases , the container div height remains the constant.
Finally i solved the problem by adding the property overflow hidden in the container div.

Here is the solution i solve the problem of Css height auto not working

    .container{
          height: auto;
         overflow: hidden;
         ....
         ...
 }
.leftbar{
          float:left;
         ....
         ...
 }
.rightbar{
        float:right;
.....
}

How to show html code on a web page |php

When you are displaying the data into the website , sometime it is necessary to write the HTML code as it is. Specially when you are trying to explain the html code through the website. There are various way you can write but for me that i like the most :
1. Begin and end all tags with &lt and &gt
2. Or include that code in the textarea.
Simply
to insert a “<" you will have to type in &lt semicolon and for ">” type &gt semicolon in YOUR html code

that should do the trick, the ampersand and the semi-colon are both required
you will write like this < h1 > hi php fresher < /h1 >
Similar Links
1.Plus2net
2. Digital Point Forum
3. Web Master World

How to make site fast By minimizing HTTP Request

80% of the end-user response time is spent on the front-end. Most of this time is tied up in downloading all the components in the page: images, stylesheets, scripts, Flash, etc. Reducing the number of components in turn reduces the number of HTTP requests required to render the page. This is the key to faster pages.

One way to reduce the number of components in the page is to simplify the page’s design. But is there a way to build pages with richer content while also achieving fast response times? Here are some techniques for reducing the number of HTTP requests, while still supporting rich page designs.

Combined files are a way to reduce the number of HTTP requests by combining all scripts into a single script, and similarly combining all CSS into a single stylesheet. Combining files is more challenging when the scripts and stylesheets vary from page to page, but making this part of your release process improves response times.

CSS Sprites are the preferred method for reducing the number of image requests. Combine your background images into a single image and use the CSS background-image and background-position properties to display the desired image segment.

Image maps combine multiple images into a single image. The overall size is about the same, but reducing the number of HTTP requests speeds up the page. Image maps only work if the images are contiguous in the page, such as a navigation bar. Defining the coordinates of image maps can be tedious and error prone. Using image maps for navigation is not accessible too, so it’s not recommended.

Inline images use the data: URL scheme to embed the image data in the actual page. This can increase the size of your HTML document. Combining inline images into your (cached) stylesheets is a way to reduce HTTP requests and avoid increasing the size of your pages. Inline images are not yet supported across all major browsers.

Reducing the number of HTTP requests in your page is the place to start. This is the most important guideline for improving performance for first time visitors. As described in Tenni Theurer’s blog post Browser Cache Usage – Exposed!, 40-60% of daily visitors to your site come in with an empty cache. Making your page fast for these first time visitors is key to a better user experience.
Extracted From