i want answer for this question(urgent)

Discussion in 'PHP' started by harshpatel1431, Aug 24, 2010.

  1. harshpatel1431

    harshpatel1431 New Member

    Joined:
    Aug 24, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    1). Explain following function with example?
    1).charactarct, 2)substr(php),3)sqrt,4)Array(php)
    2). Explain onblur and change event with example?

    pls reply me urgent
     
  2. harshpatel1431

    harshpatel1431 New Member

    Joined:
    Aug 24, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    1). Explain following function with example?
    1).charactarct, 2)substr(php),3)sqrt,4)Array(php)
    2). Explain onblur and change event with example?

    pls reply me urgent
     
  3. johnny.dacu

    johnny.dacu New Member

    Joined:
    Jul 6, 2010
    Messages:
    88
    Likes Received:
    4
    Trophy Points:
    0
    For this question always you can find answers on PHP manual.
    But i never heard charactarct...
     
  4. pein87

    pein87 Active Member

    Joined:
    Aug 6, 2010
    Messages:
    173
    Likes Received:
    47
    Trophy Points:
    28
    Occupation:
    Web Dev
    Location:
    Limbo
    simple your first function does not exist in php.

    Second substr() lets you grab text from another text based on its start point and end point. This is based on the total number of characters in the text. substr() takes 3 arguments the first being the original text, the second the start point as a number, and the end point as a number. It expects you to know the character length of your text before hand. Every text is counted for its character count, meaning text in php is made up of individual characters, and characters are letters, numbers and symbols.

    PHP:
    <?php

    $someText 
    "boooooo fire ghost";

    $getGhost substr($someText,13,17);

    echo 
    $getGhost;

    ?>
    the above code would show

    Code:
    ghost
    in a browser. What it did was it took the input text 'boooooo fire ghost' and gave me the 'ghost' text out of the original text. Because the g is the 13th character I used 13 and then used 17 which is the last character in the original text and it gave me all the characters between 13 and 17 which ended up being 'ghost'. If you count the number of characters including spaces its 18 but computers start from 0 and go up so you have to subtract the number by one to get the computer number.

    Third sqrt() is the math function square root and only excepts numbers. I dont know your level of math but square root is the number times itself that equals the current number being asked its square root.

    PHP:
    <?php

    $squareroot 
    sqrt(1987);

    echo 
    $squareroot;

    ?>
    this would show

    Code:
    44.575778176045
    and if you take out your calculator and did 44.575778176045 * 44.575778176045 it would equal 1987.

    Fourth an array is away to list/group values together. PHP supports numbered arrays, associative arrrays, and multi-dimensional arrays. to declare an array simple create a variable and use either the array function or the square brackets with a value inside to create an array.

    PHP:
    <?php

    // numbered array example

    $myarray1 = array("me","myself","i");

    $myarray2[0] = "me";
    $myarray2[1] = "myself";
    $myarray2[2] = "i";

    print_r($myarray2);

    // asscociative array example

    $myarray3["me"] = "myself";
    $myarray3["myself"] = "i";
    $myarray3["i"] = "me";

    print_r($myarray3);

    ?>
    the first two examples show you how to make an array that is ordered by number. The first example does not let you control the number each value is stored at, but the second version the [] or square brackets hold the array index or key which is how you would reference it in the code. Instead of using the variable you would use

    PHP:
    <?php

    // numbered array example

    $myarray1 = array("me","myself","i");

    $myarray2[0] = "me";
    $myarray2[1] = "myself";
    $myarray2[2] = "i";

    print_r($myarray2);

    // asscociative array example

    $myarray3["me"] = "myself";
    $myarray3["myself"] = "i";
    $myarray3["i"] = "me";

    print_r($myarray3);
    echo 
    $myarray2[2]; 
    ?>
    this would return

    Code:
    i
    In the last version you can make the index or key a word so your arrays can be better suited for your code, so instead of using the number you would use the name of the index or key.

    PHP:
    <?php

    // numbered array example

    $myarray1 = array("me","myself","i");

    $myarray2[0] = "me";
    $myarray2[1] = "myself";
    $myarray2[2] = "i";

    print_r($myarray2);

    // asscociative array example

    $myarray3["me"] = "myself";
    $myarray3["myself"] = "i";
    $myarray3["i"] = "me";

    print_r($myarray3);
    echo 
    $myarray3["me"];
    ?>
    shows

    Code:
    myself

    fifth onblur and onchange are used on input boxes in html.

    HTML:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>Untitled 3</title>
    </head>
    
    <body>
    <form method="post" action="#">
    <input type="text" value="username" onfocus="if(this.value == 'username') this.value = '';" onblur="if (this.value == '') this .value = 'username';" onchange="if (this.value == 'pein87') window.alert('welcome back pein-sama');" />
    <input type="password" />
    </form>
    </body>
    
    </html>
    as you can see if you save the above as a .html file and open it in the browser and click into the first input box it will become blank. if you click out of the input box it will show 'username' again. If you type pein87 in the first input box and click the second input box a pop up will say welcome pein-sama. onfocus simply means when the focus is on that input item and for text boxes it means when you click in it. onblur is when that item loses focus and you click another item or the page. onchange means just that when you change from one item to another. Check the code out for yourself to see how it works and these features are javascript not php.

    There explained and exampled.
     
    shabbir likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice