Pages

Monday, February 17, 2014

Program which produces its own source code as output.

This c program produces its own source code as its output
such a program is called a quine.This kind of program takes no input and produces a copy of its own source code as its only output.


#include <stdio.h>
int main(){
FILE  *fp;
char c;
fp=fopen(_FILE_,"r");
do{
       c=getc(fp);
       putchar(c);

}while(c!=EOF)

fclose(fp);
return 0;

}


output

#include <stdio.h>
int main(){
FILE  *fp;
char c;
fp=fopen(_FILE_,"r");
do{
       c=getc(fp);
       putchar(c);

}while(c!=EOF)

fclose(fp);
return 0;

}


Thursday, February 13, 2014

Google's Goglogo

Its a very interesting and entertaining application.Goglogo is a Google logo maker. It allows you to create Google style search engine for yourself. You can use your name or any name of your choice in place of google.
I tried this trick and it works fine.Its fun.I am sure you will like it too.

Follow following steps.
















2.Enter your name or name of your choice.
3.Click on create my search page now.





Monday, January 02, 2012

Program for odd and even number

This program determines wether a given number is odd or even.

#include<stdio.h>

void main(){
int num;
clrscr();
printf("Enter number : ");
scanf("%d",&num);
if(num%2==0)
printf("%d is an even number");
else
printf("%d is an odd number");
getch();

}

output:

Enter number : 4
4 is an even number

Enter number : 71
71 is an odd number


This program finds out odd or even numbers within a range

#include<stdio.h>

void main(){
int min,max,num;
clrscr();
printf("Enter minimum range : ");
scanf("%d",&min);
printf("Enter maximum range : ");
scanf("%d",&max);

printf("\nEven numbers in given range are : ");
for(num=min;num<=max;num++)
if(num%2==0)
printf("%d ",num);
printf("\n\nOdd numbers in given range are : ");

for(num=min;num<=max;num++)
if(num%2!=0)
printf("%d ",num);
getch();

}

output:

Enter minimum range 2
Enter maximum range 20

Even numbers in given range are : 2 4 6 8 10 12 14 16 18 20

Odd numbers in given range are : 1 3 5 7 9 11 13 15 17 19

Adding 1 to each digit of a number

This program adds 1 to each digit of the number.


If a five digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits.For example if the number that is input is 12391 then the output should be displayed as 23402


Here first we have added one to each digit. If any digit becomes 10 then replacing it with 0

#include<stdio.h>
void main(){

long r,num,temp,sum=0,i,temp_sum=0;
clrscr();

printf("Enter 5 digit number : ");
scanf("%ld",&num);

printf("\nThe number after adding 1 to each digit : ");

while(num!=0){
r=num%10;
temp=r+1;
if(temp==10)
temp=0;
num=num/10;
sum=(sum*10)+temp;

}

while(sum!=0){
i=sum%10;
sum=sum/10;
temp_sum=(temp_sum*10)+i;
}
printf("%ld",temp_sum);
getch();

}


output:

Enter 5 digit number : 12345
The number after adding 1 to each digit : 23456

Enter 5 digit number : 12935
The number after adding 1 to each digit : 23046

Tuesday, December 27, 2011

Program to find Armstrong number

Definition :

From c's programming point of view, Those numbers whose sum of the cube of its digits is equal to that number are known as Armstrong numbers .
For example

153 = 1^3 + 5^3 + 3^3 = 1+ 125 + 9 =153
or
370 = 3^3 + 7^3 + 0^3 = 27 + 343 + 0 = 370

But in general the definition is :

Those numbers whose sum of its digits to power of number of its digits is equal to that number are known as Armstrong numbers.

Let k be the number of digits in a number, n, and d1,d2,d3,d4... be the digits of n.
n=d1k+d2k+d3k+d4k+...


Write a C program to check whether a number is Armstrong or not.


#include<stdio.h>

void main(){
int num,sum=0,temp,i;
clrscr();
printf("Enter number: ");
scanf("%d",&num);

temp=num;
while(num!=0){
i=num%10;
num=num/10;
sum=sum+(i*i*i);

}

if(sum==temp)
printf("%d is an Armstrong number",temp);
else
printf("%d is not a Armstrong number",temp);
getch();

}


Output:

Enter number: 153
153 is an Armstrong number

Enter number: 207
207 is not a Armstrong number

Armstrong number in c using for loop

#include<stdio.hgt;

void main(){
int temp,sum=0,i,num;
clrscr();

printf("Enter number : ");
scanf("%d",&num);

for(temp=num;num!=0;num=num/10){
i=num%10;
sum=sum+(i*i*i);

}
if(temp==sum)
printf("%d is an Armstrong Number ",temp);
else
printf("%d is not a Armstrong Number ",temp);
getch();

}

Thursday, December 22, 2011

Program to find sum of all digits of a number

This program calculates the sum of all digits of a number into a single digit.for instance if user has input 2345..the end result will be 2345=14=5


If a number of any digit is iput through keyboard,write a program to obtain the sum of all digits of the number into a single digit


#include<stdio.h>
void main()
{
long num,temp,total=0,r,sum=0;
clrscr();

printf("Enter the number : ");
scanf("%ld",&num);

// it will give sum of all digits
while(num!=0)
{
r=num%10;
num=num/10;
total=total+r;

}

// This will further sum up the total of digits
while(total!=0)
{
temp=total%10;
total=total/10;
sum=sum+temp;
}

printf("Total=%ld ",sum);
getch();

}

Program to find sum of first and last digit of a number of any digit

This program finds the sum of first and last digit of a number that would be of any length


If a number of any digit is input through the keyborad,write a program to obtain the sum of first and last digit of this number.


#include<stdio.h>

void main(){

/*
since integer range is between -32768 to 32767
it will support till 5 digit number only
so for higher digits you have to declare
with long
*/

long firstdigit,sum=0,r,num;
clrscr();

printf("Enter number : ");
scanf("%ld",&num);

sum=sum+num%10; // num%10 gives lastdigit

while(num!=0){
firstdigit=num; // gives first digit
num=num/10;
}

sum=sum+firstdigit;

printf("Sum of first and last digit : %ld",sum);
getch();


}

Saturday, December 17, 2011

Program to reverse input number

This program reverse the input number.

If a five-digit number is input through the keyboard,write a program to reverse the number

#include<stdio.h>
#include<conio.h>
void main()
{
long num,r;
long sum=0;
clrscr();

printf("Enter number : ");
scanf("%ld",&num);


while(num!=0)
{
r=num%10;
num=num/10;

sum=(sum*10)+r;

}
printf("%ld",sum);

getch();
}

Friday, December 16, 2011

Program to calculate sum of digits of a number

This program calculates sum of any digit number(within integer range).since integer range is-32768 to 32767,it gives error wen number exceeds 5 digit....

#include<stdio.h>
void main()
{
int num,r;
int sum=0;
clrscr();

printf("Enter number : ");
scanf("%d",&num);

while(num!=0)
{
r=num%10;
num=num/10;
sum=sum+r;
}
printf("%d",sum);

getch();
}

Program to calculate sum of 5-digit number

This program calculates sum of five digit number enterd through keyboard

If a five-digit number is input through the keyboard,write a program to calculate the sum of its digits
#include<stdio.h>
void main()
{
int num,next_num,last_num,total;
clrscr();

printf("Enter the number : ");
scanf("%d",&num);

last_num=num%10;
total=last_num;

next_num=(num/10)%10;
total=total+next_num;

next_num=(num/100)%10;
total=total+next_num;

next_num=(num/1000)%10;
total=total+next_num;

next_num=(num/10000)%10;
total=total+next_num;
printf("\nThe sum of entered 5 digit number is : %d",total);

getch();

}

Program to interchange two values

This program interchanges two values input through keyboard

Two numbers are input through the keyboard into two locations C and D.Write a program to interchange the contents of C and D

#include<stdio.h>
void main()
{
int C,D,temp;
clrscr();
printf("Enter value of C and D :");
scanf("%d %d",&C,&D);
temp=C;
C=D;
D=temp;
printf("\nThe interchanged value of C and D are %d %d",C,D);
getch();

}

Saturday, November 12, 2011

Program to calculate area,perimeter of rectangle and circumference ,area of circle (Ref:Let us c-chapter1)

This program calculates the area and perimeter of a rectangle and circumference and area of a circle.

The length and breadth of a rectangle and radius of a circle are input through the keyboard.Write a program to calculate the area and perimeter of the rectangle,and the area and circumference of the circle.

#include<stdio.h>


void main()
{

float length,breadth,radius,rec_area,circle_area,perimeter,circumference;

clrscr();

printf("Enter length and breath for rectangle:");
scanf("%f%f",&length,&breadth);

printf("Enter radius for circle:");
scanf("%f",&radius);

rec_area=length*breadth;
perimeter=2*(length+breadth);

circle_area=3.14*radius*radius;
circumference= 2*3.14*radius;

printf("\n\nArea of rectancle is : %f",rec_area);
printf("\n\nPerimeter of rectangle is : %f",perimeter);

printf("\n\nArea of circle is : %f",circle_area);
printf("\n\nCircumference of circle is : %f",circumference);

getch();

}

Program to convert Farenhite temperature into Celcius temperature and vice-versa (Ref:Let us c-chapter1)

This program convert entered Farenhite temperature into centigrade temperature or vice-versa.


Temperature of a city in Farenhite degrees is input through the keyboard.Write a program to convert this temperature into centigrade degrees.


Note:To convert Fahrenheit to Celsius, subtract 32 degrees  and divide by 1.8.
while for converting Celsius to Fahrenheit, multiply by 1.8 and add 32 degrees


#include<stdio.h>


void main()


{


float temp_f,temp_c;


clrscr();


printf("Enter the value of temperature in Celcius:");


scanf("%f",&temp_c);


temp_f=(1.8*temp_c)+32;


printf("The value of temperature in Fahrenheit is :%f",temp_f);


getch();


}

Monday, November 07, 2011

Program for aggregate marks and percentage calculation
(Ref: Let us c-chapter1)


This program calculates the total and percentage marks.


If the marks obtained by a student in five different subjects are input through the keyboard, find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.




#include<stdio.h>


void main()
{
int m1,m2,m3,m4,m5,total;
float prcnt;
clrscr();
printf("Enter marks for first subject:");
scanf("%d",&m1);
printf("Enter marks for second subject:");
scanf("%d",&m2);
printf("Enter marks for third subject:");
scanf("%d",&m3);
printf("Enter marks for fourth subject:");
scanf("%d",&m4);
printf("Enter marks for fifth subject:");
scanf("%d",&m5);
total=m1+m2+m3+m4+m5;
prcnt=total/5;
printf("Total marks obtained by the student is :%d",total);
printf("\nPercentage is:%f ",prcnt);


getch();


}

Monday, June 27, 2011

Distance Converter Program(Ref: Let us c-chapter1)
This program converts the entered value into meters,feet,inches and centimeters

The distance between two cities (in km) is input through the keyboard. Write a program to convert and print this distance in meters,feet,inches and centimeters.

#include<stdio.h>

/*
1 kilometer=39370 inches
1 kilometer=3281 Feet
1 kilometer=100000 centimeters
1 kilometer=1000 meters

*/

void main()
{
float km,meter,feet,inches,centimeter;
clrscr();
printf("Enter the distance between two cities:");
scanf("%f",&km);

meter=1000*km;
centimeter=100000*km;
inches=39370*km;
feet=3281*km;

printf("\nThe Entered distance between two cities in meter is:%f",meter);
printf("\nThe Entered distance between two cities in centimeter is:%f",centimeter);
printf("\nThe Entered distance between two cities in inches is:%f",inches);
printf("\nThe Entered distance between two cities in feet is:%f",feet);

getch();
}
Gross Salary Program(Ref: Let us c-chapter1)

This program calculate gross salary of an employee if his basic slaray is input thru keyboard.


Ramesh's basic salary is input throught the keyboard.His dearness allowance is 40% of basic salary,and house rent allowance is 20% of basic salary.Write a program to calclate gross salary.

#include<stdio.h>
void main()
{

float bs,gs,hra,da;
clrscr();
printf("Enter basic salary:");
scanf("%f",&bs);
hra=bs*20/100;
da=bs*40/100;
gs=bs+hra+da;
printf("Gross salary= %f",gs);
getch();
}

Friday, March 06, 2009

How To Add YUI Treeview menu in your page...



Sometimes in our project we need to add menus
and submenus...so instead of writing long javascript
code(if you are a damm good javascript programmer) or
Scritping code,ts far better to use YAHOO User interface tool...
It contains lots of many useful tools and reduce rather saves
our time a lot..so the first example of YUI that i gonna share with
u all is the Treeview Menu...


Its very simple..just follow the steps or instruction given below




  • Copy the YUI folder to your root directory..You can download it from http://developer.yahoo.com/yui/


  • Now open the page in which you want to add this tool..
    like i hv added this tool in a CMS in which many sub links were there..


  • Add the code in header section of ur page

    <link rel='stylesheet' type='text/css'
    href='../yui/build/fonts/fonts-min.css' />

    <link rel="stylesheet" type="text/css"
    href="../yui/build/treeview/assets/skins/sam/treeview.css"/>

    <script type="text/javascript"
    src="../yui/build/yahoo/yahoo-min.js"/></script/>

    <script type="text/javascript"
    src="../yui/build/event/event-min.js"/></script/>

    <script type="text/javascript"
    src="../yui/build/treeview/treeview-min.js"/></script/>

    <style/> #treeDiv1 {background: #E4DDC0; padding:1em;} </style/>



  • Add below given line at the place where you want the tree..

    Like in my case i have placed the tree in left section of my page..
    <div id="treeDiv1" style="background-color:#E4DDC0"/></div/>


  • Add this javascript code at the end of the page




<script type="text/javascript"/>
//global variable to allow console inspection of tree:
var tree;
//anonymous function wraps the remainder of the logic:
(function() {
//function to initialize the tree:
function treeInit() {
buildRandomTextNodeTree();
}

//Function creates the tree and
//builds between 3 and 7 children of the root node:
function buildRandomTextNodeTree() {


//instantiate the tree:
tree = new YAHOO.widget.TreeView("treeDiv1");


var n =new YAHOO.widget.TextNode("<a href='#'/>Home</a>" ,tree.getRoot(), false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=School'/>› School View</a>" , n, false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=Tour'/>› Virtual Tour</a>" , n, false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=Pricipal'/>› Principal Desk</a>" , n, false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=SiteMap'/>› Site Map</a>" , n, false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=contactus'/>› Contact Us</a>" , n, false);


var n =new YAHOO.widget.TextNode("<a href='#'/>Our School</a>" ,
tree.getRoot(), false);

new YAHOO.widget.
TextNode("<a href='edit-content.php?page=Vision'/>› Our Vision</a>" , n, false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=Location'/>› Location</a>" , n, false);
new YAHOO.widget.TextNode("<a href='edit-content.php?page=History'/>› History</a/>" , n, false);
new YAHOO.widget.TextNode("<a href='edit-content.php?page=Terms'/>› School Terms</a/>" , n, false);
var n =new YAHOO.widget.TextNode("<a href='#'/>Infrastructure</a/>" , tree.getRoot(), false);
new YAHOO.widget.TextNode("<a href='edit-content.php?page=Library'/>› Library</a/> " , n, false);
new YAHOO.widget.TextNode("<a href='edit-content.php?page=Computerlab'/>› Computer & Science Lab</a>" , n, false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=Mathslab'/>› Maths Lab</a> " , n, false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=Conference'/>› Conference Room</a> " , n, false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=Auditorium'/>› Auditorium</a> " , n, false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=Playground'/>› Playground</a> " , n, false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=Transport'/>› Transport</a> " , n, false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=Medical'/>› Medical</a> " , n, false);

var n =new YAHOO.widget.TextNode("<a href='edit-content.php?page=Staff'/>Staff</a> " , tree.getRoot(), false);

var n =new YAHOO.widget.TextNode("<a href='#'/>Academics</a>" , tree.getRoot(), false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=Education'/>› Education</a> " , n, false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=Curriculum'/gt;› Curriculum</a/> " , n, false);
new YAHOO.widget.TextNode("<a href='edit-content.php?page=Computer'/>›Computer</a> " , n, false);

var n =new YAHOO.widget.TextNode("<a href='#'/>Beyond Academics</a>" , tree.getRoot(), false);
new YAHOO.widget.TextNode("<a href='edit-content.php?page=Sports'/>› Sports </a/> " , n, false);
new YAHOO.widget.TextNode(" <a href='edit-content.php?page=Arts'/>› Arts & Crafts </a/>" , n, false);
new YAHOO.widget.TextNode("<a href='edit-content.php?page=Elocution'/>› Elocution</a/> " , n, false);
new YAHOO.widget.TextNode("<a href='edit-content.php?page=Music'/>› Music & Drama</a> " , n, false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=Scouts'/>› Scouts & Guides</a/> " , n, false);
new YAHOO.widget.TextNode("<a href='edit-content.php?page=Counselling'/gt;rsaquo; Counselling</a/> " , n, false);

var n =new YAHOO.widget.TextNode("<a href='#'/>Enrollment</a>" , tree.getRoot(), false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=Fee'/>› Fee Structure </a/> " , n, false);

new YAHOO.widget.TextNode(" <a href='edit-content.php?page=Uniforms'/>› Uniforms </a> " , n, false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=Books'/>› Book List </a> " , n, false);

var n =new YAHOO.widget.TextNode("<a href='#'/>Boarding</a>" , tree.getRoot(), false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=Fee'/>› Fee Structure </a> " , n, false);

new YAHOO.widget.TextNode(" <a href='edit-content.php?page=Uniforms'/>› Uniforms </a/> " , n, false);

new YAHOO.widget.TextNode("<a href='edit-content.php?page=Books'/>› Book List </a/> " , n, false);

var n =new YAHOO.widget.TextNode("<a href='#'/>School System</a>" , tree.getRoot(), false);

new YAHOO.widget.TextNode(" <a href='edit-content.php?page=Prefectorial'/>› Prefectorial System </a>" , n, false);

var n =new YAHOO.widget.TextNode("<a href='#'/>Policies</a>" , tree.getRoot(), false);
new YAHOO.widget.TextNode("<a href='edit-content.php?page=ChildPro'/>› Child Protection </a> " , n, false);

new YAHOO.widget.TextNode(" <a href='edit-content.php?page=SubstanceAbuse'/>› Substance Abuse </a> " , n, false);

// Expand and collapse happen prior to the actual expand/collapse,
// and can be used to cancel the operation
tree.subscribe("expand", function(node) {
YAHOO.log(node.index + " was expanded", "info", "example");
// return false; // return false to cancel the expand
});

tree.subscribe("collapse", function(node) {
YAHOO.log(node.index + " was collapsed", "info", "example");
});

// Trees with TextNodes will fire an event for when the label is clicked:
tree.subscribe("labelClick", function(node) {
YAHOO.log(node.index + " label was clicked", "info", "example");
});

//The tree is not created in the DOM until this method is called:
tree.draw();
}


//Add an onDOMReady handler to build the tree when the document is ready
YAHOO.util.Event.onDOMReady(treeInit);

})();

</script/>


6. Thats it just refresh the page..and you are done..






Tuesday, July 29, 2008

Generating select box from class.(PHP5)

How many times we need to write selectbox code 0n our page.
Lets say in my website there are 10 pages where i need select box for country.
so writing same code on all of 10 page is very iritating job.
the best way is to write either a function or class for that. with object-oriented concept of php 5 we can tremendously reduce that tedious code on every page.

just make a class file for that contains functions for every selectbox.

like if u want a country selectbox then

make a class file , call that class on ur page and aha!!!
you got the box. no need to write time and again same code on every page.


just type or copy this code for class file

class Select_Option_Class {

public function buildCountrySelect($country_id = false, $selectName = 'country') {
$this->countrySelect = '';
$sql = 'SELECT * FROM country ORDER BY printable_name';
$result = mysql_query($sql);
if (!$result || !mysql_num_rows($result)) return false;

while ($row = mysql_fetch_array($result)) {
$this->countrySelect .= ''."\n"; }
$this->countrySelect = ''."\n";
return $this->countrySelect;
}

}

include following line in ur config file so that you don't need to call it on every page

require_once('admin/class/Select_Option_Class.php');
$selectOption = new Select_Option_Class();

now finally use this line on ur page to call the function

echo $selectOption->buildFrontCountrySelect($country);


thats it.

here u can find that instead of writing selectbox code on every page. u are done with just a single line code.

enjoy coding!!!!!!!!!!!!!!!!!



Monday, July 28, 2008

PHP Interview Questions

1. What are the differences between GET and POST methods in form submitting, give the case where we can use get and we can use post methods?

Ans.On the server side, the main difference between GET and POST is where the submitted is stored. The $_GET array stores data submitted by the GET method. The $_POST array stores data submitted by the POST method.
On the browser side, the difference is that data submitted by the GET method will be displayed in the browser’s address field. Data submitted by the POST method will not be displayed anywhere on the browser.GET method is mostly used for submitting a small amount and less sensitive data. POST method is mostly used for submitting a large amount or sensitive data

2. Who is the father of php and explain the changes in php versions?
Ans.Rasmus Lerdorf for version changes go to http://php.net/ Marco Tabini is the founder and publisher of phparchitect.

3. How can we submit from without a submit button?
Ans.We can use a simple JavaScript code linked to an event trigger of any form field. In the JavaScript code, we can call the document.form.submit() function to submit the form. For example:

4. How many ways we can retrieve the date in result set of mysql Using php?
Ans.As individual objects so single record or as a set or arrays.

5. What is the difference between mysql_fetch_object and mysql_fetch_array?
Ans.MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array.

6. What is the difference between $message and $$message?
Ans.They are both variables. But $message is a variable with a fixed name. $$message is a variable who’s name is stored in $message. For example, if $message contains "var", $$message is the same as $var.

7. How can we extract string ‘abc.com ‘ from a string ‘http://info@a…’ using regular _expression of php?
Ans.We can use the preg_match() function with "/.*@(.*)$/" as the regular expression pattern. For example: preg_match("/.*@(.*)$/","http://info@abc.com",$data); echo $data[1];

8. How can we create a database using php and mysql?
Ans.PHP: mysql_create_db()Mysql: create database;

9. What are the differences between require and include, include_once?
Ans.File will not be included more than once. If we want to include a file once only and further calling of the file will be ignored then we have to use the PHP function include_once(). This will prevent problems with function redefinitions, variable value reassignments, etc.

10. Can we use include ("abc.php") two times in a php page "makeit.php"?
Ans.Yes we can include..
11. What are the different tables present in mysql, which type of table is generated when we are creating a table in the followingsyntax: create table employee(eno int(2),ename varchar(10)) ?
Ans.Total 5 types of tables we can create
1. MyISAM
2. Heap
3. Merge
4. InnoDB
5. ISAM
6. BDBMyISAM is the default storage engine as of MySQL 3.23.

12. How can I execute a php script using command line?
Ans.Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, "php myScript.php", assuming "php" is the command to invoke the CLI program.Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.

13. Suppose your ZEND engine supports the mode Then how can u configure your php ZEND engine to support mode ?
Ans.If you change the line: short_open_tag = off in php.ini file. Then your php ZEND engine support only mode.

14. What is meant by nl2br()?
Ans.nl2br — Inserts HTML line breaks before all newlines in a string string nl2br (string); Returns string with ‘’ inserted before all newlines. For example: echo nl2br("god bless\n you") will output "god bless \n you" to your browser.

15. What are the reasons for selecting lamp (Linux, apache, mysql, php) instead of combination of other software programs, servers and operating systems?
Ans.All of those are open source resource. Security of linux is very very more than windows. Apache is a better server that IIS both in functionality and security. Mysql is world most popular open source database. Php is more faster that asp or any other scripting language.

16. How can we encrypt and decrypt a data present in a mysql table using mysql?
Ans.AES_ENCRYPT () and AES_DECRYPT ()

17. How can we encrypt the username and password using php?
Ans.You can encrypt a password with the following Mysql>SET PASSWORD=PASSWORD("Password");We can encode data using base64_encode($string) and can decode using base64_decode($string);

18. What are the features and advantages of OBJECT ORIENTED PROGRAMMING?
Ans.One of the main advantages of OO programming is its ease of modification; objects can easily be modified and added to a system there by reducing maintenance costs. OO programming is also considered to be better at modeling the real world than is procedural programming. It allows for more complicated and flexible interactions. OO systems are also easier for non-technical personnel to understand and easier for them to participate in the maintenance and enhancement of a system because it appeals to natural human cognition patterns.For some systems, an OO approach can speed development time since many objects are standard across systems and can be reused. Components that manage dates, shipping, shopping carts, etc. can be purchased and easily modified for a specific system.
19. What are the differences between PROCEDURE ORIENTED LANGUAGES and OBJECT ORIENTED LANGUAGES?
Ans.Traditional programming has the following characteristics:
Functions are written sequentially, so that a change in programming can affect any code that follows it.If a function is used multiple times in a system (i.e., a piece of code that manages the date), it is often simply cut and pasted into each program (i.e., a change log, order function, fulfillment system, etc). If a date change is needed (i.e., Y2K when the code needed to be changed to handle four numerical digits instead of two), all these pieces of code must be found, modified, and tested.Code (sequences of computer instructions) and data (information on which the instructions operates on) are kept separate. Multiple sets of code can access and modify one set of data. One set of code may rely on data in multiple places. Multiple sets of code and data are required to work together. Changes made to any of the code sets and data sets can cause problems through out the system.
Object-Oriented programming takes a radically different approach:
Code and data are merged into one indivisible item – an object (the term "component" has also been used to describe an object.) An object is an abstraction of a set of real-world things (for example, an object may be created around "date") The object would contain all information and functionality for that thing (A dateobject it may contain labels like January, February, Tuesday, Wednesday. It may contain functionality that manages leap years, determines if it is a business day or a holiday, etc., See Fig. 1). Ideally, information about a particular thing should reside in only one place in a system. The information within an object is encapsulated (or hidden) from the rest of the system.A system is composed of multiple objects (i.e., date function, reports, order processing, etc., See Fig 2). When one object needs information from another object, a request is sent asking for specific information. (for example, a report object may need to know what today’s date is and will send a request to the date object) These requests are called messages and each object has an interface that manages messages.OO programming languages include features such as "class", "instance", "inheritance", and "polymorphism" that increase the power and flexibility of an object.

20. What is the use of friend function?
Ans.Friend functionsSometimes a function is best shared among a number of different classes. Such functions can be declared either as member functions of one class or as global functions. In either case they can be set to be friends of other classes, by using a friend specifier in the class that is admitting them. Such functions can use all attributes of the class whichnames them as a friend, as if they were themselves members of that class.A friend declaration is essentially a prototype for a member function, but instead of requiring an implementation with the name of that class attached by the double colon syntax, a global function or member function of another class provides the match.class mylinkage{private:mylinkage * prev;mylinkage * next;
protected:friend void set_prev(mylinkage* L, mylinkage* N);void set_next(mylinkage* L);
public:mylinkage * succ();mylinkage * pred();mylinkage();};
void mylinkage::set_next(mylinkage* L) { next = L; }
void set_prev(mylinkage * L, mylinkage * N ) { N->prev = L; }Friends in other classes
It is possible to specify a member function of another class as a friend as follows:class C{friend int B::f1();};class B{int f1();};It is also possible to specify all the functions in another class as friends, by specifying the entire class as a friend.class A{friend class B;};
Friend functions allow binary operators to be defined which combine private data in a pair of objects. This is particularly powerful when using the operator overloading features of C++. We will return to it when we look at overloading.

21. What are the different types of errors in php?
ans.Three are three types of errors:
1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although, as you will see, you can change this default behaviour.
2. Warnings: These are more serious errors - for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.
3. Fatal errors: These are critical errors - for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP's default behaviour is to display them to the user when they take place.

22. What is the functionality of the function strstr and stristr?
Ans.strstr() returns part of a given string from the first occurrence of a given substring to the end of the string. For example: strstr("user@example.com","@") will return "@example.com".stristr() is idential to strstr() except that it is case insensitive.

23. What is the functionality of the function htmlentities?
Ans: htmlentities — Convert all applicable characters to HTML entitiesThis function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

24. How can we get second of the current time using date function?
$second = date("s");

25. What is meant by urlencode and urldocode?
Ans.urlencode() returns the URL encoded version of the given string. URL coding converts special characters into % signs followed by two hex digits. For example: urlencode("10.00%") will return "10%2E00%25?. URL encoded strings are safe to be used as part of URLs.urldecode() returns the URL decoded version of the given string.

26. What is the difference between the functions unlink and unset?
Ans.unlink() deletes the given file from the file system.unset() makes a variable undefined.

27. How can we register the variables into a session?
Ans.We can use the session_register ($ur_session_var) function.

28. How can we get the properties (size, type, width, height) of an image using php image functions?
Ans.To know the Image type use exif_imagetype () functionTo know the Image size use getimagesize () functionTo know the image width use imagesx () functionTo know the image height use imagesy() function

29. What is the maximum size of a file that can be uploaded using php and how can we change this?
Ans.You can change maximum size of a file set upload_max_filesize variable in php.ini file

30. How can we increase the execution time of a php script?
AnsSet max_execution_time variable in php.ini file to your desired time in second.

31. How can we take a backup of a mysql table and how can we restore it.?
Answer: Create a full backup of your database: shell> mysqldump –tab=/path/to/some/dir –opt db_name Or: shell> mysqlhotcopy db_name /path/to/some/dirThe full backup file is just a set of SQL statements, so restoring it is very easy:shell> mysql "."Executed";mysql_close($link2);


32. How many ways can we get the value of current session id?
Ans session_id() returns the session id for the current session.

33. How can we destroy the session, how can we unset the variable of a session?
Ans session_unregister — Unregister a global variable from the current sessionsession_unset — Free all session variables

34. How can we destroy the cookie?
Ans Set the cookie in past

35. How many ways we can pass the variable through the navigation between the pages?
Ans GET or QueryString and POST46. What is the difference between ereg_replace() and eregi_replace()?Ans:-eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic characters.eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic characters.