Monday, 29 October 2012

Random Number Genrate According To Your Varaible

Following Code Used for gen-ratting random number according to you want. If you want to alphabet and numeric comes together and want to give limit of both, like numeric shows 2 value and alphabet shows 3 value, then you can use this random number system.

1. This is very simple random number function and will help you for password generation or  some other task.

2. You can define your character for generation character, For example you need to change following variable.


  $character_set_array = array( );
  $character_set_array[ ] = array( 'count' => 3, 'characters' => 'abcdefghijklmnopqrstuvwxyz' );
  $character_set_array[ ] = array( 'count' => 3, 'characters' => '0123456789' );
  $character_set_array[ ] = array( 'count' => 3, 'characters' => '!@#$&*' );
  $character_set_array[ ] = array( 'count' => 3, 'characters' => '<>?":{}/;'"' );

So then function chose character from every character set but only 3 char from every, Because there is count given 3. So only three character choose from every one.

Function given in following text area just select all, copy and paste in your page. Now just echo function.





 Following, I am giving some output of the function.

  1.  3!:{u#1>yk#1

  2.  &$1l?7]*yo?2

  3. "c]86i!@"*7g

  4.  <@{>6f&h1h4@

  These are the output of the above function.


Thursday, 25 October 2012

Ajax Library

Ajax is very important for websites development. It's work without refreshing the page of websites.

Following is given ajax function.

This will compatible with all browsers like opera, mozila firefox, chrome, IE7 and above.

just copy all code which is given in text area.

How to use this ajax is following. Follow step by step.


1. Copy all code from above text area and paste it on a page and save as ajax.js

2. Include this file on your page, where you want to ajax effect.

3. You can use this in js function as following.

      function checkEmail(email){
             var ajax = new Ajax();
             ajax.doGet('validateUser.php?checkUserEmail='+email,checkEmailNow,'text');
     } 


4. Now ajax is object and ajax.doGet means ajax call its doGet function.

5. validateUser.php is your page from where you need to get response.

6. Now checkUserEmail is request where we send user email .

7. checkEmailNow taking response from this page.

8.  Now how to use response, check following..

     var checkEmailNow = function(str){
             if(str == 0){
                   return false;
             }else{

                   return true;
             }
     }

9. This is ajax function and great function and compatible with all browsers.

10. This is javascript part so work carefully because single error create you problem.

How to show & hide overlay on onclick

When you display some important data and form like login etc, then you need to overlay hide and show on javascript function onClick.

At following, I am giving proper overlay code.

Javascript :   There is given javascript function, which used to show and hide overlay through onClick. There is given to function, these are following.

  1. function loginForm(){
              document.getElementById("contentWrap").style.display="block";
              document.getElementById("overlay").style.display="block";

      }

For showing overlay and content.

2.  function loginFormClose(){
        document.getElementById("contentWrap").style.display="none";
        document.getElementById("overlay").style.display="none";
    }


For hiding overlay and content.


CSS :  Overlay effect shown due to style property, following css used for overlay display.

.overlay  { 
                   background:#000; 
                   opacity:0.8; 
                   filter:alpha(opacity=80);
                   position:fixed;
                   top:0px; 
                   bottom:0px;
                   left:0px; 
                   right:0px;
                   z-index:100; 
                }

 .contentWrap {

                          position:fixed;
                          top:50px; 
                          color:#7F7F7F; 
                          z-index:101; 
                          width:100%; 
                           margin:0 auto
                        }


Following is total code, just copy from text area and run browser and check how is this working.



Hope so it will helpful to you and following is screen shot of working site.

1.

2.
 
Above is overlay effect showing.

Enable For Numeric Value in Input type

Following script used only enable numeric value in input type.

Allow :  only 0 to 9 numeric value.

Allow : backspace, delete, tab and escape

Allow : Ctrl+A

Allow : home, end, left, right


Script is following, just copy all code from textarea




This script help you, when you made input type text for pone number.

 This enable only for numeric value.

Friday, 19 October 2012

How to read special character in php

Some time you store data in different language like French, Spanish etc.When you fetch this data on your page then the special character are not shown as they save in data base.They shows on page as question mark etc,this is problem is utf encode. If you are using xampp version of 1.7.3 and above then there is no problem because when you are fetching data from database then it's return encoded data then data shows in right way.But when your special character are not shown. So don't worry and no need to install latest xampp/wampp.Following are the special characters and method how to show this in our page.

a) Umlauts and accents:- Â Ã Ä Æ Ç È É Ñ Õ Ö Ø Ù Ú Û Ü ß ã ñ ò ó ô œ õû ü ÿ
b) Punctuation:- ¿ ¡ « » § ¶ † ‡ • - – —
c) Commercial symbols:- ™ © ® ¢ € ¥ £ ¤
d) Greek characters:- a ß ? d e ? ? ? ? µ ? p ? s t ? f ? ?G ? T ? ? ? S F ? O
e) Math characters:- ? ? ? v - ± 8 ˜ ? = ? = = × · ÷ ? ? ? ? ? ? ? ? ?

For that there is following ways for showing special characters.

1. utf8_encode()
2. header('Content-Type: text/html; charset=utf-8');


1. utf8_encode():- This is used with variable, for example if there is a variable
$userPassword = "#ÛÜõû!";
if these special character not print in your page then you need to used this function as following.
echo utf8_encode($userPassword);
Now it's print #ÛÜõû! on your page.


2. charset=utf-8:- Another way is just place this code on your page at the top once time header('Content-Type: text/html; charset=utf-8'); , then your special character shows on your page.
header('Content-Type: text/html; charset=utf-8');
But you can use utf8_encode() it's more predictable and accurate.

you can use both of this but I suggest you you can use utf8_encode() and it's solve your problem. Use this with variable where you wants to echo.

Difference between Foreach and For Loop:-

$array = array("Surinder","Rahul","Manoj","Bharti","Rana","Manish"); Foreach($array as $name )
{
echo "Employe Name is ".$name.".";
}
This will print as following.
Employe Name is Surinder.
Employe Name is Rahul.
Employe Name is Manoj.
Employe Name is Bharti.
Employe Name is Rana.
Employe Name is Manish.

$array = array("Surinder","Rahul","Manoj","Bharti","Rana","Manish");
For($i=0;$i<6;$i++)
{
echo "Employe Name is ".$array[$i].";
}
At the place of 6,You can used count array function.
This will print as following.
Employe Name is Surinder.
Employe Name is Rahul.
Employe Name is Manoj.
Employe Name is Bharti.
Employe Name is Rana.
Employe Name is Manish.
These are the difference between Foreach and for loop.