PHP Interview- Favicon ICon

String-Function

$ext = strrchr($filename, ".");
echo $ext; // will return ".gif"
 
<?php
function getDomainFromEmail($email)
{
// Get the data after the @ sign
$domain = substr(strrchr($email, "@"), 1);

return $domain;
}

// Example

$email = 'the_username_here@yahoo.com';

$domain = getDomainFromEmail($email);

echo $domain; // yahoo.com
?>; 

 API STANDS FOR
Application programming interface (API)
API specifies a set of functions or routines that accomplish a specific task or are allowed to interact with a specific , API in procedural languages

PHP 5 Array Functions

Splits an array into chunks of arrays

<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43","Harry"=>"50");
print_r(array_chunk($age,2,true));
?>

The array_change_key_case() function changes all keys in an array to lowercase or uppercase.
 <?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
print_r(array_change_key_case($age,CASE_UPPER));
?>

OP/ Array ( [PETER] => 35 [BEN] => 37 [JOE] => 43 ) 

array_pop()
The array_pop() function deletes the last element of an array.
<?php
$a=array("red","green","blue");
array_pop($a);
print_r($a);
?>

OP/ Array ( [0] => red [1] => green ) 


The array_product() function calculates and returns the product of an array.

<?php
$a=array(5,5);
echo(array_product($a));
?>
 


array_push() 
Inserts one or more elements to the end of an array 
<?php
$a=array("red","green");
array_push($a,"blue","yellow");
print_r($a);
?> 


The array_slice() function returns selected parts of an array.
 <?php
$a=array("red","green","blue","yellow","brown");
print_r(array_slice($a,2));
?>

OP/ Array ( [0] => blue [1] => yellow [2] => brown ) 

Returns the sum of the values in an array

The array_sum() function returns the sum of all the values in the array.
<?php
$a=array(5,15,25);
echo array_sum($a);
?>
OP/45

arsort

Sort an associative array in descending order, according to the value:
 <?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
arsort($age);

foreach($age as $x=>$x_value)
    {
    echo "Key=" . $x . ", Value=" . $x_value;
    echo "<br>";
    }
?>



The list() function is used to assign values to a list of variables in one operation.

 $my_array = array("Dog","Cat","Horse");

list($a, $b, $c) = $my_array;
echo "I have several animals, a $a, a $b and a $c.";


OP/I have several animals, a Dog, a Cat and a Horse. 




STRING FUNCTION



$stringA = "user@example.com";
$toFind = "@";

 $result = strchr($stringA,$toFind,true);user

 $result = strrchr($stringA,$toFind); //@example.com

 $stringA="ramiz Ramiz";
 $toFind="R"
 $strstr=strstr($stringA,$toFind);// case sensitive Ramiz

 $stringA="ramiz Ramiz";
 $toFind="R"
 $strstr=stristr($stringA,$toFind);//this is not case sensitice  ramiz Ramiz




The chop() function removes whitespaces or other predefined characters from the right end of a string.
 <?php
$str = "Hello World!";
echo $str . "<br>";
echo chop($str,"World!");
?>

OP/Hello World!
Hello





 htmlentities()
<?php
$str = "<© W3Sçh°°¦§>";
echo htmlentities($str);
?> OP/ &lt;&copy; W3S&ccedil;h&deg;&deg;&brvbar;&sect;&gt;

echo html_entity_decode($str);

REVERSE AS ABOVE EX.

htmlspecialchars_decode

<?php
$str = "This is some &lt;b&gt;bold&lt;/b&gt; text.";
echo htmlspecialchars_decode($str);
?>
 

Object Oriented Concepts:

Before we go in detail, lets define important terms related to Object Oriented Programming.
  • Class: This is a programmer-defined datatype, which includes local functions as well as local data. You can think of a class as a template for making many instances of the same kind (or class) of object.
  • Object: An individual instance of the data structure defined by a class. You define a class once and then make many objects that belong to it. Objects are also known as instance.
  • Member Variable: These are the variables defined inside a class. This data will be invisible to the outside of the class and can be accessed via member functions. These variables are called attribute of the object once an object is created.
  • Member function: These are the function defined inside a class and are used to access object data.
  • Inheritance: When a class is defined by inheriting existing function of a parent class then it is called inheritance. Here child class will inherit all or few member functions and variables of a parent class.
  • Parent class: A class that is inherited from by another class. This is also called a base class or super class.
  • Child Class: A class that inherits from another class. This is also called a subclass or derived class.
  • Polymorphism: This is an object oriented concept where same function can be used for different purposes. For example function name will remain same but it make take different number of arguments and can do different task.
  • Overloading: a type of polymorphism in which some or all of operators have different implementations depending on the types of their arguments. Similarly functions can also be overloaded with different implementation.
  • Data Abstraction: Any representation of data in which the implementation details are hidden (abstracted).
  • Encapsulation: refers to a concept where we encapsulate all the data and member functions together to form an object.
  • Constructor: refers to a special type of function which will be called automatically whenever there is an object formation from a class.
  • Destructors: refers to a special type of function which will be called automatically whenever an object is deleted or goes out of scope.
-------------------------------------------------------------------------------------------------------------
http://favicon-generator.org/

<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">

No comments:

Post a Comment