what is chr() function in PHP ? How to get character value from ASCII value?

31 Dec

In PHP chr() function is used to get character from the given ASCII character.

Lets have an example for chr() function to get corresponding result :

<?php
$data1 = chr(65);
$data2 = chr(90);
$data3 = chr(64);

echo $data1."<br />";
echo $data2."<br />";
echo $data3."<br />";
?>

Output of above an example will be:

A
Z
@

Even using chr()  and rand() function we can generate captcha for human verification code.

Lets have an example for the same:

<?php
$data = "";
for($i = 1 ; $i<=5 ;$i++)
{
   $data.= chr( rand(65,90) );
}
echo " Captcha generated by random function and chr function is : ".$data
?>

From the given above example we understand that $data will have total 5 random character from ASCII value 65 to 90 ( i.e  from A to Z ) using rand() function.

rand() function in php will generate number from the given range. ( i.e. 65 to 90 in the given example ).

Now this random will get converted in character using chr() function of PHP.

Output of above example will be :

Captcha generated by random function and chr function is : ABDTP

What is constant in PHP ? what is define() function in php ?

31 Dec

Constant is different from variables .

Difference between constant and variable is : variable can have different value mean variable value can be modified. but constant value can not be modified once it is defined

Constants are named values whose values cannot be changed.

When we create constant we use all capital letters and underscore to represent constant. Dollar sign is not required in front of the constant name.

We use define() function to create constant

Lets have an example to initialize constant :

 <?php 

//define(constant_name, value, case_sensitive=true); 
define("TECHNOLOGY", "Javascript", true); 

echo "Given Technology is: " . TECHNOLOGY ;

?> 

Output :

Given Technology is: Javascript

what is in_array() function in php ?

27 Dec

In php , in_array() function is used to search record from specified array .If that record found in an array then , in_array() function will return TRUE , else it will return FALSE.

Syntax :
<?php
in_array( specific record , array );
?>

Output :

bool ( TRUE or FALSE )

Lets have the following example:

Example :
$languages = array("PHP","MySQL","Ajax","Javascript");

if (in_array("MySQL", $languages)) {
    echo "MySQL record found in given array";
}
Answer : 
In the above example $languages is defined as an array with 4 different value.
In the if condition in_array() is used to check MySQL keyword within $languages array.
Since MySQL is present in $languages.
Output will be :
MySQL record found in given array

What is short tags in php.ini | Enabling Short Tags in PHP

27 Dec

Generally we use tags ,

<?php
?>

short_open_tag : It is a configuration directive in php.ini file. It will describe PHP whether the short form (<? ?>) of PHP’s open tag should be allowed or not.

for php code. php.ini will provide you to enable PHP short tags ( <? ?> ).

PHP.ini allows you the option to use short style opening tags for PHP code blocks e.g. <? instead of <?php.

To activate this feature , we have to open php.ini file from the Xampp server path ( i.e. etc folder in Linux operating system ) and ( php folder in windows operating system ) and search for the following command .

short_open_tag = off .

change the short_open_tag setting to:

short_open_tag=On

Note :

it is not generally advised to use Short Tags as this can lead to future problems when migrating to server that doesnt have short_open_tag enabled.

What is the difference between include and require?

21 Dec

Include it is a part of control structure in PHP.

Include is used to evaluate or get specific file from the given path.

e.g:

include 'forloop.php'

or

include('forloop.php')

In the above example forloop.php is included in the current file.

IMP :  If the given path or file is not available . The include will show warning as an output .

Warning will not affect other code which is going to be executed after include statement

e.g

Warning: include(forloop.php) [function.include]: 
failed to open stream:

————————————————————————————————-

require it is a part of control structure in PHP.

Require is used to evaluate or get specific file from the given path.

e.g:

require 'forloop.php'

or

require ('forloop.php')

In the above example forloop.php is included in the current file.

IMP :  If the given path or file is not available . The require will show fatal error as an output .

Fatal error will stop entire file execution . mean after this line none of the line will get executed

e.g

Fatal error: require(forloop.php) [function.require]: 
failed to open stream:

Note :  Its always better to use require instead of include to get proper result.

What is the Difference Between get , post and request method ?

21 Dec

In HTML to transfer records from one page to another page , attribute method is used in form tag.

i.e :

<form method="post" action="action.php">
data goes here .......
</form>

Now , In this case action.php is destination page where user will have records .

in PHP : there are 3 methods to retrieve data from receiving page.

1 ) $_GET

2) $_POST

3) R_REQUEST

$_GET :

$_GET is a super global array which is an inbuilt array. Which collects values from a form sent with method=”get” as well it collects values from URL also. ( e.g. http://www.domainname.com/pagename.php?data=123)

You can print $_GET with inbuilt function in php i.e ( print_r($_GET) ).

IMP : Information sent from this method will be visible in ( address bar of any browser ) and has limitation on characters .

As per W3C Community limitation can be extended up to 4000 characters

Myth: Search services will not index anything with a “?” in the URI.
Myth: URIs cannot be longer than 256 characters
for details : visit : About $_GET limitation :

You can read more details about $_GET.

$_POST :

$_POST is a super global array which is an inbuilt array. Which collects values from a form sent with method=”post”.

You can print $_GET with inbuilt function in php i.e ( print_r($_POST)  ).

IMP : Information received from POST method is always invisible in ( address bar of any browser ) . It has more limit on sending characters to action page.

This limitation can be set in php.ini file

Note: We can change by setting the POST_MAX_SIZE in the php.ini file . by default we will find this value with 8MB in most of the php.ini file.

$_REQUEST :

$_REQUEST is a super global array which is an inbuilt array. Which collects values from a form sent with  either method=”post” or method=”get” .

You can print $_REQUEST with inbuilt function in php i.e ( print_r($_REQUEST)  ).

IMP : One of the best way of getting data on action page , here we did not require to check that which method we have used to pass data from sending page.Even $_REQUEST get records from the COOKIE also.

What is foreach loop in PHP?

20 Dec

PHP is full equipped language with good number of inbuilt function and properties.

Since PHP is with 3 types of array like , Numeric array , Associative Array and Mixed Array.

To get data from array foreach loop can be used which is specially designed to retrieve records from complex structure like array and array of objects etc..

Definition of Foreach Loop :

foreach( array_name as array_key => array_value){
expression 1;
expression 2;
.........
expression n;
}

Description :

Input of foreach loop is any array i.e array_name having combination of array key and array value. foreach loop will iterate till the numer of records available inside given array.

Output of foreach loop will be key and value of given array.

array_key will handle offset value of an array which is called as key

array_value will handle actual record which is called as value.

( => ) is called as associative operator in PHP.

Associative operator ( => ) is used to link the relation between key and value e.g ( [0] => PHP  where 0 is the key and PHP is its value).

Example of Foreach Loop:

$country = array("India" , "United States" , "Nepal" , "Brazil" );
foreach( $country as $value)
{
echo $value;
echo "<br />";
}

Explanation :

In the above example , $country is an array having total 4 value .

When we do foreach loop , foreach loop will first count the number of records available in $country array . Then it will extract one by one record in $value. so the answer of above example will be displayed as below:

Answer :

India 
United States
Nepal
Brazil

What is PHP ? Who is the founder of PHP?

20 Dec

PHP is created by Rasmus Lerdorf in 1995 . Intially PHP was considered as language for personal home page ( PHP ) .

It is one of the first server side scripting language which is designed for web based application . PHP Full form is : ( Hyper Text Preprocessor ). It is one of the fastest and best language which can be implement and embedded into HTML ( i.e. Hyper text markup language ). PHP code is interpreted by PHP parser which is located with web server on server side.

Along with PHP We can use ( Open source technology and technique like MYSQL database , Javascript , Ajax , HTML , CSS , JQuery etc..) to built large scale application.

PHP also includes command line interface module and also standalone shell on every operating system. PHP is a part GNU (GNU General Public License)  Foundation which is famous for open source community.

In PHP we can can learn procedure oriented programming , Object Oriented Programming , Also MVC architecture is with full support in PHP.

In php , on mvc architecture zend framework , Code Igniter Framework , Kohana Framework , Symphony Framework , Code Igniter Framework  , YII Framework , and many more …… are available.

Even PHP has very good Content Management System like Drupal , Joomla  and wordpress.

PHP is with very famous E-commerce like Magento ,  Opencart , Zen cart etc…

PHP is installed on more than 30 million Web sites and 1.5 million web server.