CONCEPTS ON FUNCTIONS AND IT'S USES ALONG WITH FUNCTION EXAMPLE, URL, FORM ALONG WITH FORM EXAMPLES
CONCEPTS ON FUNCTIONS AND IT'S USES ALONG WITH FUNCTION EXAMPLE, URL, FORM ALONG WITH FORM EXAMPLES
So, first I am going to explain about the concepts of functions and it's uses along with an example of function.
So, function is basically a reusable block of code which performs specific tasks. Function is used in all types of programming language like C,Java,Python,PHP,etc. Function is basically a separate chapter in a book. Like in PHP we have functions like array functions which includes array_push() function, array_pop() function, array_shift() function,array_unshift() function and in PHP we also have functions like string functions which includes ucfirst() function, lcfirst() function,ucwords() function, lcwords() function, etc. We also have functions in PHP OOP's (Object Oriented Programming's) concepts in constructor like function __construct() function, function display() function where __construct() is a magic keyword which is denoted by double underscore(__) function which example I will show you after sometime. And here constructor is basically a function which creates objects. Constructor allows to initialise the objects by itself which means that if we create any objects in a class, constructor is called first. Now coming to the use of function. So, function is used to call the function values and to return the function values. Now coming to an example of function. So, if you ask me about an example of function, I can show you a proper example of function of constructor in PHP OOP's concepts(Object Oriented Programming's) with function __construct() and with function display(). So, let's begin with an example of function.
For example:
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<form method="post">
Name: <input type="text" name="name"><br>
Email: <input type="email" name="email"><br>
Phone: <input type="number" name="phone"><br>
Age: <input type="number" name="age"><br>
<button type="submit" name="submit" value="submit>Submit</button>
</form>
<?php
if(isset($_REQUEST['submit']))
{
$Name=$_REQUEST['name'];
$Email=$_REQUEST['email'];
$Phone=$_REQUEST['phone'];
$Age=$_REQUEST['age'];
class StudentForm
{
function __construct($Name,$Email,$Phone,$Age)
{
$this->na=$Name;
$this->em=$Email;
$this->ph=$Phone;
$this->ag=$Age;
}
function display()
{
echo $this->na."<br>".$this->em."<br>".$this->ph."<br>".$this->ag;
}
}
$obj=new StudentForm($Name,$Email,$Phone,$Age)
$obj->display();
}
?>
</body>
</html>
Now coming to the concepts of URL. So, URL is basically known as Uniform Resource Locator which is basically used to search any kinds of websites like ejobindia,capgemini,tcs,wipro,infosys,etc. As well as URL is also used in query string. So, now just let me explain quickly about the query string in url. So, query string is basically a part of the url which starts after the question mark(?).
For example:
http://example.com/page.php?name=Ayan Bhattacharjee&email=ayanbhattacharjee1997@gmail.com
<?php
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
echo "Name: " . $name . "<br>";
echo "Email: " . $email;
?>
Output:
Name: Ayan Bhattacharjee
Email: ayanbhattacharjee1997@gmail.com
Query String is used in GET METHOD as because GET METHOD can only pass the query string where query string is not supported in POST METHOD as because POST METHOD cannot pass any query string. As because POST METHOD is the most secure method so it cannot pass query string whereas GET METHOD is the unsecure method so it can pass query string. We can pass query string in $_GET()or in $_REQUEST().
As bacause $_REQUEST() supports in both $_GET() METHOD as well as in $_POST() METHOD.
Now coming to the concepts of form and it's example. So, what is form?
Form is basically a structure which is used to design the input fields in a form type which we put in the input fields. Form basically helps to make the input fields in a proper form structure. Like in form I used to have method as post which is the most secure method and in post method we cannot pass any query string and post method doesnot have any limit as well as in form I used to have action like action="formaction.php" or action="editaction.php" which formaction.php or editaction.php we used to create after form page or edit page to call and print the values. Then in form tag I also used to have enctype="multipart/form-data" for image because I know that simple normal text can be converted in binary very easily but for file type as because image or file or pdf this are all file type, so this file type cannot be converted in binary very easily that's why I have used the file type as enctype="mutipart/form-data" where enctype stands for encrypt type.
For Example:
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<form method="post" action="formaction.php" enctype="multipart/form-data">
Name: <input type="text" name="name"><br>
Email: <input type="email" name="email"><br>
Phone: <input type="number" name="phone"><br>
Age: <input type="number" name="age"><br>
Password: <input type="password" name="pass"><br>
Image: <input type="file" name="image"><br>
</body>
</html>
So, with this I am ending the concepts on functions and it's uses along with function example, url, form along with form examples.
Comments
Post a Comment