Go4Expert

Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   i want answer for this question(urgent) (http://www.go4expert.com/forums/i-answer-question-urgent-t23083/)

harshpatel1431 24Aug2010 08:52

i want answer for this question(urgent)
 
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

harshpatel1431 24Aug2010 08:52

Re: i want answer for this question(urgent)
 
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

johnny.dacu 25Aug2010 00:23

Re: i want answer for this question(urgent)
 
For this question always you can find answers on PHP manual.
But i never heard charactarct...

pein87 31Aug2010 23:47

Re: i want answer for this question(urgent)
 
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 Code:

<?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 Code:

<?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 Code:

<?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 Code:

<?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 Code:

<?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 Code:

<!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.


All times are GMT +5.5. The time now is 02:20.