PHP Flashcards

1
Q

PHP

A
  1. Hypertext preprocessor
  2. widely used open source scripting language
  3. PHP Scripts are executed on server
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

php file

A
  1. Contains text ,html, css, js and php.
  2. Pagep is executedon server and result is executed to browser as plain html
  3. Extension .php
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

ADV of PHP

A
  1. PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
  2. PHP is compatible with almost all servers used today (Apache, IIS, etc.)
  3. PHP supports a wide range of databases
  4. PHP is free. Download it from the official PHP resource: www.php.net
  5. PHP is easy to learn and runs efficiently on the server side
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

features of php

A
  • PHP can generate dynamic page content
  • PHP can create, open, read, write, delete, and close files on the server
  • PHP can collect form data
  • PHP can send and receive cookies
  • PHP can add, delete, modify data in your database
  • PHP can be used to control user-access
  • PHP can encrypt data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

basic syn of php

A

<?php
|

|
?> is syn

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

echo

A

Predefined function that is used to output the text on web page

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Other array functions

A
  1. array()
  2. array_change_key_case_()
  3. array_chunks()
  4. array_search()
  5. array_reverse()
  6. sorting(6)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

array()

A

creates and returns an array
syn=arrayname=array(values_ _)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

array_change_key_case()

A

Changes the case of the all keys
syn: array_change_key_case( $arrayname, case_lower)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

array_chunks()

A

Divides the array into smaller chunks
syn: array_chunks($arrayname_,no))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

array_reverse()

A

function returns an array containing elements in reversed order
syn: array_reverse($arrayname)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

array_search()

A

searches the specified value in an array. It returns key if search is successful
syn: array_search(“valuetosearch”,$arrayname)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

sorting array functions

A
  1. sort()
  2. rsort()
  3. asort()
  4. arsort()
  5. aksort()
  6. krsort()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

php functions

A

1.piece of the code that can be reused many times.
2.takes input as args and returns the value.

Advantages:
1. code reusability
2. less code
3. easy to understand

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

function declaration

A

function functionname()
{
//code to execute
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

php function arguments

A

-supports :
1. call-by value
2. call-by reference
3. default args,
4. variable-length

(Same as py)

17
Q

call by value

A
  1. functionname(“value”)
18
Q

call by reference

A

1.“&” is used while declaring variables in the fun
2. we use another variable to collect the value
syn ++
function funcname(&$_ _ _)
{
//code
}
obj=value
funname($function name)

19
Q

parametrized function

A
  1. Functions with parameters
  2. You can pass any number of parameters in a function
  3. These passed parameters act as variables inside the function
  4. These are specified inside parenthesis after the function name
  5. Output depends upon the dynamic values passed as the parameters into function
20
Q

Cookie

A
  1. small piece if info which is stored at client browser.
  2. used to recogonize the user
  3. cookie is created at client browser, each time when client sends request to the server, cookie is embedded with req—such that cookie can be recieved at the server side.
  4. cookie can be created, sent and recieved at server end.
21
Q

session

A
  1. used to store and pass info from one page to another temporarily(until user close the website)
  2. php session technique is widely used in shopping where we need to store and pass cart information(eg: username, product code, product name, product price, etc)f om one page to another.
    3.php creates unique user id for each browser to recogonize the user and avoid conflict between multiple browsers.
22
Q

session functions

A

1.session_start(): Starts in new or resumes session if session is created already session_start();
2.$SESSION: associative array that contains all session variables–used to set and get session vari values
store info: $session[“user”] =”value”
to get info: echo $SESSION[“user”];
3. destroying session: Destroy all session variables completely —session_destroy()

23
Q

session eg

A

File: session1.php
1. <?php
2. session_start();
3. ?>
4. <html>
5. <body>
6. <?php
7. $_SESSION[“user”] = “Sachin”;
8. echo “Session information are set successfully.<br></br>”;
9. ?>
10. <a>Visit next page</a>
11. </body>
12. </html>
Save this code with session2.php
13. ?php
14. session_start();
15. ?>
16. <html>
17. <body>
18. <?php
19. echo “User is: “.$_SESSION[“user”];
20. ?>
21. </body>
22. </html>

24
Q

Math functions

A

Provides many predefined math functions in constants that can be used to perform mathematical operations
1. abs()
2. ceil()
3. floor()
4. sqrt()

25
Q

regular expr(pattern search)

A
  1. Also called as rejex
  2. Pattern or a sequence of characters which describe a special search pattern as text string
    functions :
  3. Allows you to search specific string inside another string
  4. Replace one string by another
  5. Split strings into multiple chunks

-uses arth operators (+,-,^)To create complex expressions
- By default these are case sensitive

26
Q

adv of regex

A
  1. Helps programmers to validate text strings
  2. Offers a powerful tool to analyse and search a pattern as well as modify the text str
  3. By using rejects functions we can get simple and easy solutions to identify patterns
  4. Helps creating html template system recognition tags
  5. Widely used for browser detection, Firm validation spam filtration and password strength checking
  6. helpful in user input validation testing like email address mobile number and ip address
  7. Helps in highlighting the special keywords in file based upon the search result or input
  8. Meta characters allow us to create more complex patterns
27
Q

file inclusion

A

PHP allows us to create various elements and functions which are used same *several times in many pages this takes so much time to script therefore file inclusion topic is introduced

def: File inclusion helps to include files in various programmes and saves the effort of writing code multiple times
- When you want to apply the same html or php code to multiple pages of website page inclusion is used

28
Q

types of page inclusion

A
  1. include–creates a warning(E_WARNING) and continue the execution of script
  2. require– Generates a fatal error (E_COMPILE_ERROR) and stops the execution
29
Q

advantages (2)

A
  1. code reusability
  2. easy ediatability
30
Q

include and eg

A

Used to include a file on the basis of given path(relative/ abs path os a file)
Syn: —include “filename”; or
—include (“filename”);

eg: File: menu.html
<a>Home</a> |
<a>PHP</a> |
<a>Java</a> |
<a>HTML</a>
File: include1.php
<?php include(“menu.html”); ?>

<h1>This is Main Page</h1>

31
Q

require

A

Very similar to include along with the syntax and the programme the only difference is Stop execution of script if the file is not found whereas include doesn’t
Syn: —require “filename”; or
—require (“filename”);
eg:File: menu.html
<a>Home</a> |
<a>PHP</a> |
<a>Java</a> |
<a>HTML</a>
File: require1.php
<?php require(“menu.html”); ?>

<h1>This is Main Page</h1>

32
Q

PHP include vs PHP require

A

Both include and require are same. But if the file is missing or inclusion
fails, include allows the script to continue but require halts the script producing a fatal
E_COMPILE_ERROR level error.
Let’s understand the difference with the help of example:
Example
include.php
1. <?php
2. //include welcome.php file
3. include(“welcome.php”);
4. echo “The welcome file is included.”;
5. ?>
Output:
The welcome.php file is not available in the same directory, which we have included. So,
it will produce a warning about that missing file but also display the output.
Warning: include(welcome.php): failed to open stream: No such file or directory
in C:\xampp\htdocs\program\include.php on line 3
Warning: include(): Failed opening ‘welcome.php’ for inclusion
(include_path=’C:\xampp\php\PEAR’) in C:\xampp\htdocs\program\include.php on
line 3
The welcome file is included.
require.php
1. <?php
2. echo “HELLO”;
3. //require welcome.php file
4. require(“welcome.php”);
5. echo “The welcome file is required.”;
6. ?>
Output:
In case of require() if the file (welcome.php) is not found in the same directory. The
require() will generate a fatal error and stop the execution of the script, as you can see
in the below output.
HELLO
Warning: require(Welcome.php): failed to open stream: No such file or directory
in C:\xampp\htdocs\program\include.php on line 3
Fatal error: require(): Failed opening required ‘Welcome.php’ (include_path

.

33
Q

file handling

A

php file system allows us to create file, read file line by line, read file character by character, write file, append file, delete file and Close file
1. fopen(“path”,”mode”)
2. fclose($handle)
3. string fread( resource $handle, int $length)
4. fwrite($filename, value)
5. unlink(filename, value)—del