BookMyShow – PHP Web Developer interview questions and answers

1) swap value of  a and b without using third variable ?

For integer values  :
$a = 10;
$b = 25;

$a = $a + $b ;  // a = 35
$b = $a – $b ;  // b = 10
$a = $a – $b ;  // a = 25

For any values :
list ($a , $b) = array ($b, $a);

2) difference between public and prviate ?

public scope to make that variable/function available from anywhere, other classes and instances of the object.

private scope when you want your variable/function to be visible in its own class only.

protected scope when you want to make your variable/function visible in all classes that extend current class including the parent class.

3)include & require difference ?

Include will includes a file each time it is called. when included file is not available it gives a warning.

Require is like include, but if the file included is not available a fatal error occurs and processing stops.

4)how to suppress warning errors ?

In PHP.ini we can set error setting to  ~E_WARNING.

5)why class is needed ? how to call a method from another class ?
Classes are needed to represent the structure or behavior of any object.

  • Class is a User Defined Data type.
  • Class is a collection of data and methods.

 

and some technical analysis questions are asked based on some example code.

Robert Bosch – Front end / Javascript developer interview questions and answer

1)explain javascript inheritance ?

JavaScript does not have “methods” in the form that class-based languages define them. In JavaScript, any function can be added to an object in the form of a property. An inherited function acts just as any other property When an inherited function is executed, the value of this points to the inheriting object, not to the prototype object where the function is an own property.

var o = { a: 2, m: function(b){ return this.a + 1; } };

console.log(o.m()); // 3 // When calling o.m in this case, ‘this’ refers to o

var p = Object.create(o); // p is an object that inherits from o

p.a = 12; // creates an own property ‘a’ on p console.log(p.m()); // 13 // when p.m is called, ‘this’ refers to p. // So when p inherits the function m of o, ‘this.a’ means p.a, the own property ‘a’ of p

2) Diff b/w $document.ready and window.onload and body onload event ? Windows load event fires when all the content on your page fully loaded including the DOM (document object model) content, asynchronous JavaScript, frames and images, you can also use body onload= both are same just window.onload = func(){} and are different ways of using the same event.

jQuery $document.ready function event executes a bit earlier than window.onload and called once the DOM(Document object model) is loaded on your page. It will not wait for the images, frames to get fully load.

3)explain Javascript static variables and methods ? Static variables and methods

Static variables Static methods

A function is an object. That provides us with a very good way to create static variables or the variables which persist along multiple calls.

For example, we want a variable which counts function calls. Static variables

There are languages which allow to put a static keyword before a variable, and then such variable is not cleared in next calls.

Example of a static variable in PHP language: 1 function f() { // PHP code! 2 static $count = 0; 3 4 echo ++$count; 5 } 6 7 f(); f(); f(); // 1 2 3

In JavaScript, there is no term or keyword static, but we can put such data directly into function object (like in any other object).

1 function f() { 2 f.count = ++f.count || 1 // f.count is undefined at first 3 4 alert(“Call No ” + f.count) 5 } 6 7 f(); // Call No 1 8 f(); // Call No 2

Of course, a global variable can keep the counter, but static variables lead to a better architecture.

We could make the code more universal by replacing f with arguments.callee.

1 function f() { 2 arguments.callee.count = ++arguments.callee.count || 1 3 4 alert(“Called ” + arguments.callee.count + ” times”) 5 }

Now you can safely rename the function if needed Smile Static methods

Static methods, just like variables, are attached to functions. They are used mostly for objects:

01 function Animal(name) { 02 arguments.callee.count = ++arguments.callee.count || 1 03 04 this.name = name 05 } 06 07 Animal.showCount = function() { 08 alert( Animal.count ) 09 } 10 11 var mouse = new Animal(“Mouse”) 12 var elephant = new Animal(“elephant”) 13 14 Animal.showCount() // 2

for more info : http://javascript.info/tutorial/static-variables-methods-decorators

4) If both parent and child element have onclick event , when you click on child , parent onclick event also loads. how to disable it ?

using event.stopPropagation() we can stop the event bubbling up in DOM tree. $( .childelementclass ).click(function( event ) { event.stopPropagation(); // Do something });

For more info : http://api.jquery.com/event. stopPropagation/

5) What does the $ sign mean in Jquery ?

The $ is just a function. It is actually an alias for the function called jQuery, so your code can be written like this with the exact same results:

jQuery(‘#Text’).click(function () { jQuery(‘#Text’).css(‘color’, ‘red’); });

In jQuery the variable is assigned a copy of the jQuery function. This function is heavily overloaded and means half a dozen different things depending on what arguments it is passed. In this particular example you are passing it a string that contains a selector, so the function means “Create a jQuery object containing the element with the id Text”

6) explain javascript namespace ? “what is a namespace?” A namespace is a container and allows you to bundle up all your functionality using a unique name. In JavaScript, a namespace is really just an object that you’ve attached all further methods, properties and objects. Creating a namespace for your code helps prevent the overwriting of existing function names. It’s also a step in the object-oriented direction, which promotes modularity and code re-use.

7) whather Javascript supports block level scope or not ? Blocks do not have scope in Javascript .

There is no difference between the following:

1 var i = 1 2 { 3 i = 5 4 }

…And the following 1 i = 1 2 { 3 var i = 5 4 }

All var declarations are processed before the execution in in both cases.

Unlike languages like Java, C etc, variables in JavaScript survive after a loop.

That’s again, because their scope is a function.

1 for(var i=0; i<5; i++) { } 2 3 alert(i) // 5, variable survives and keeps value

Declaring a variable in the loop is convenient, but doesn’t make the loop it’s scope. for mor einfo : http://javascript.info/tutorial/initialization#blocks-do-not-have-scope

8) why Javascript is loosely typed language ? Loose typing means that variables are declared without a type. This is in contrast to strongly typed languages that require typed declarations. /* JavaScript Example (loose typing) */var a = 13; // Number declaration var b = “thirteen”; // String declaration

/* Java Example (strong typing) */int a = 13; // int declaration String b = “thirteen”; // String declaration

Notice that in the JavaScript example, both a and b are declared as type var. Please note, however, that this does not mean that they do not have a type, or even that they are of type “var”. Variables in JavaScript are typed, but that type is determined internally. In the above example, var a will be type Number and var b will be type String. These are two out of the three primitives in JavaScript, the third being Boolean.

Type coercion is a topic that is closely associated with loose typing. Since data types are managed internally, types are often converted internally as well. 7 + 7 + 7; // = 21 7 + 7 + “7”; // = 147 “7” + 7 + 7; // = 777 In the examples above, arithmetic is carried out as normal (left to right) until a String is encountered. From that point forward, all entities are converted to a String and then concatenated.

for more info : http://blog.jeremymartin.name/2008/03/understanding-loose-typing-in.html

HCL – Web / UI Developer – interview questions and answer – HTML5 , CSS3 , JS & jQuery

1) Explain about HTML5 local storage ?

There are two ways to store data in HTML as objects locally :

  1. localStorage – store data  across session acess
  2. sessionStorage – storing data for current session only

Data will be stored in key/value pair format.

example:

localStorage.empid=”420″;

sessionStorage.companyname = “SHARAG INFOTECH”;

2)  explain CSS media queries ?

CSS media queries are used to develop responsive templates for different layout of screen, print, mobile , tablet or any other resolutions

CSS media queries can be added in 3 ways as like CSS style sheet :

  1. Internal stylesheet :  <style type=”text/css”>
    @media only screen and (max-width: 600px){
    /* rules apply to the device resolution is 480px or less  */
    }
    </style>
  2. Imported stylesheet :   @import “tablet.css”   (min-width: 800px) and (max-width: 1200px);
  3. External stylesheet:  <link rel=”stylesheet” type=”text/css” href=”deskto.css” media=”screen and (min-width: 1200px), print and (min-resolution: 300dpi)” />

3) explain css inheritance ?

Inheritance propagates property values from parent elements to their children. The inherited value of a property on an element is the computed value of the property on the element’s parent element. For the root element, which has no parent element, the inherited value is the initial value of the property.

A property can also be explicitly inherited by using the inherit keyword in property.

CSS inheritance example:
class inheritance for an HTML tag :
<div class=”firstClass secondClass thirdClass fourthClass ” > </div >
CSS property inheritance from parent :
p {
color: #000;
}
p a:link {
color: inherit;
}

and using LESS method for inheritance example:
//through variable
@color: #123456;
#emp {
color: @color;
}
div {
color: @color;
}

//through class name calling [MIXINS]

.rounded-corners (@radius: 2px) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
-ms-border-radius: @radius;
-o-border-radius: @radius;
border-radius: @radius;
}

#navtable {
.rounded-corners;
}

#maintable {
.rounded-corners(5px);
}

4) what is javascript inheritance ?

In simple terms, inheritance is the concept of one thing gaining the properties or behaviours of something else.
Inherited children inherit their parent’s behaviour To say A inherits from B, is saying that A is a type of B.
In JavaScript You must use a special object called prototype.
function Animal() {}; // This is the Animal *Type*
Animal.prototype.eat = function () {
alert(“All animals can eat!”);
};

function Bird() {}; // Declaring a Bird *Type*
Bird.prototype = new Animal(); // Birds inherit from Animal
Bird.prototype.fly = function() {
alert(“Birds are special, they can fly!”);
};

The effect of this is that any Birds you create (called an instance of Bird) all have the properties of Animals
var aBird = new Bird(); // Create an instance of the Bird Type
aBird.eat(); // It should alert, so the inheritance worked
aBird.fly(); // Important part of inheritance, Bird is also different to Animal

var anAnimal = new Animal(); // Let’s check an instance of Animal now
anAnimal.eat(); // Alerts, no problem here
anAnimal.fly(); // Error will occur, since only Birds have fly() in its prototype

5) explain javascript associative array ?

Associative arrays are where we can associate a key string with a value string
JavaScript objects are also associative arrays.
i.e the property  emp.Name can also be read by calling emp['Name']
We can access each property by entering the name of the property as a string into the array
it refers to accessing the DOM elements of HTML also [as object or associative array]
6) explain JS Namespace ?

Namespacing is a technique employed to avoid collisions with other objects or variables in the global namespace
and also helps to organize blocks of functionality into easily manageable groups that can be uniquely identified.

JavaScript doesn’t  builtin support of namespacing but using objects and closures we can achieve a similar effect.
javascript Namespacing patterns :
1)    Single global variables :
var myApplication =  (function(){
function(){
/*…*/
},
return{
/*…*/
}
})();

2)    Object literal notation :

var myApplication = {
getInfo:function(){ /**/ },
// we can also populate our object literal to support
// further object literal namespaces containing anything
// really:
models : {},
views : {
pages : {}
},
collections : {}
};

3)    Nested namespacing :

var myApp =  myApp || {};
// perform a similar existence check when defining nested
// children
myApp.routers = myApp.routers || {};
myApp.model = myApp.model || {};
myApp.model.special = myApp.model.special || {};
// nested namespaces can be as complex as required

4)    Immediately-invoked Function Expressions :

// an (anonymous) immediately-invoked function expression
(function(){ /*…*/})();
// a named immediately-invoked function expression
(function foobar(){ /*..*/}());
// this is technically a self-executing function which is quite different
function foobar(){ foobar(); }
5)   Namespace injection :

// define a namespace we can use later
var ns = ns || {}, ns2 = ns2 || {};
// the module/namespace creator
var creator = function(val){
var val = val || 0;
this.next = function(){
return val++
};

this.reset = function(){
val = 0;
}
}
creator.call(ns);

// ns.next, ns.reset now exist
creator.call(ns2, 5000);
// ns2 contains the same methods
// but has an overridden value for val
// of 5000
for more details on namespace read http://addyosmani.com/blog/essential-js-namespacing/
7) explain Jquery live and bind methods ?
.bind() attacheds events to elements that exist or match the selector at the time the call is made.
Any elements created afterwards or that match going forward because the class was changed, will not fire the bound event.

$(‘img’).bind(‘click’, function(){…});

.live() works for existing and future matching elements.
Before jQuery 1.4 this was limited to the following events:
click, dblclick mousedown, mouseup, mousemove, mouseover, mouseout, keydown, keypress, keyup
$(‘img’).live(‘click’, function(){…});

8) what is bootstrap ?

Bootstrap is an open-source Javascript framework developed by the team at Twitter.
It is a combination of HTML, CSS, and Javascript code designed to help build user interface components.
Bootstrap is Sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development.
Bootstrap was also programmed to support both HTML5 and CSS3
Bootstrap is a CSS and Javascript framework that is used within your HTML. Bootstrap provides more advanced functionality to your web site.
More details http://getbootstrap.com
9) type of webservice ?

there are two types of web service….1. SOAP [Simple Object Access Protocol] Webservice and 2. RESTful [REpresentational State Transfer] Webservice.
SOAP is a messaging protocol , REST is a design philosophy , not a protocol.
SOAP:

you define your interface in a .wsdl file, which describes exactly which input parameters are expected and how the return values will look like
there are tools to generate the .wsdl files out of java class hirarchies. JAXB for example
there are also tools to generate java objects/classes as part of eclipse for example (don’t know the name in the moment).
SOAP is very strict. Every request is validatet against the wsdl before processing.

A good but not so easy to start with framework for SOAP WS is Apache CXF

REST (no hands on experience up to now, feel free to correct and improve ;) ):

a way to access a webserver or web application to retrieve data from or send to it.
it’s only negotiated, how it is accessed.
common is something like this http://server.domain.com/app/type/id=123 to retrieve object of type type with id=123
very intuitive, but no automatic validation of requests.

The main advantages of REST web services are:

Lightweight – not a lot of extra xml markup
Human Readable Results
Easy to build – no toolkits required

SOAP also has some advantages:

Easy to consume – sometimes
Rigid – type checking, adheres to a contract
Development tools

ALL CSS Interview question and answer

1. What is CSS?
CSS stands for Cascading Style Sheets and is a simple styling language which allows attaching style to HTML elements. Every element type as well as every occurance of a specific element within that type can be declared an unique style, e.g. margins, positioning, color or size.

2. What are Cascading Style Sheets?
A Cascading Style Sheet (CSS) is a list of statements (also known as rules) that can assign various rendering properties to HTML elements. Style rules can be specified for a single element occurrence, multiple elements, an entire document, or even multiple documents at once. It is possible to specify many different rules for an element in different locations using different methods. All these rules are collected and merged (known as a “cascading” of styles) when the document is rendered to form a single style rule for each element.

3. How do I center block-elements with CSS1?
There are ways of centering block level elements:

By setting the properties margin-left and margin-right to auto and width to some explicit value:

BODY {width: 30em; background: cyan;}
P {width: 22em; margin-left: auto; margin-right: auto}

In this case, the left and right margins will each be four ems wide, since they equally split up the eight ems left over from (30em – 22em). Note that it was not necessary to set an explicit width for the BODY element; it was done here to keep the math clean.

4.If background and color should always be set together, why do they exist as separate properties?
There are serveral reasons for this. First, style sheets become more legible — both for humans and machines. The background property is already the most complex property in CSS1 and combining it with color would make it even more complex. Second, color inherits, but background doesn’t and this would be a source of confusion.

5. What is class?
Class is a group of 1) instances of the same element to which an unique style can be attached or 2) instances of different elements to which the same style can be attached.

6. What is grouping?
Grouping is gathering into a comma separated list two or more selectors that share the same style or into a semicolon separated list two or more declarations that are attached to the same selector .

1. The selectors LI, P with class name .first and class .footnote share the same style, e.g.:
LI {font-style: italic}
P.first {font-style: italic}
.footnote {font-style: italic}

To reduce the size of style sheets and also save some typing time they can all be grouped in one list.
LI, P.first, .footnote {font-style: italic}

7. What is external Style Sheet? How to link?
External Style Sheet is a template/document/file containing style information which can be linked with any number of HTML documents. This is a very convenient way of formatting the entire site as well as restyling it by editing just one file. The file is linked with HTML documents via the LINK element inside the HEAD element. Files containing style information must have extension .css, e.g. style.c ss.

<LINK rel=stylesheet type=”text/css” href=”style.css“>

8. Is CSS case sensitive?
Cascading Style Sheets (CSS) is not case sensitve. However, font families, URLs to images, and other direct references with the style sheet may be.

9. What is CSS rule ‘ruleset’?
There are two types of CSS rules: ruleset and at-rule. Ruleset identifies selector or selectors and declares style which is to be attached to that selector or selectors. For example P {text-indent: 10pt} is a CSS rule. CSS rulesets consist of two parts: selector [ e.g. P ] and declaration [ e.g. {text-indent: 10pt}] .

P {text-indent: 10pt} – CSS rule (ruleset)
{text-indent: 10pt} – CSS declaration
text-indent – CSS property
10pt – CSS value

10. ‘Fixed’ Background?
There is the possibility to use the HTML tag bgproperties=”fixed”, but that is IE proprietary, and dependent upon the ‘background’ attribute (deprecated in HTML4).

With CSS, you can declare the background like:

BODY {
font-family : “Trebuchet MS”, Verdana, Arial, Helvetica, sans-serif;
background-image: url(images/yourimage.gif);
background-repeat: no-repeat; /*no-tiling background*/
background-position: center;
background-attachment: fixed;
background-color: #hexcolor;
color : #hexcolor;
margin: 10px;
}

that shows a background-image in the center of the element, non-scrolling and non-repeating – in IE or NN6. NN 4.xx gets the non-repeat-part right, but stuffs the picture in the upper left corner and scrolls ..

11. What is embedded style? How to link?
Embedded style is the style attached to one specific document. The style information is specified as a content of the STYLE element inside the HEAD element and will apply to the entire document.

Note: The styling rules are written as a HTML comment, that is, between to hide the content in browsers without CSS support which would otherwise be displayed.

12. What is ID selector?
ID selector is an individually identified (named) selector to which a specific style is declared. Using the ID attribute the declared style can then be associated with one and only one HTML element per document as to differentiate it from all other elements. ID selectors are created by a character # followed by the selector’s name. The name can contain characters a-z, A-Z, digits 0-9, period, hyphen, escaped characters, Unicode characters 161-255, as well as any Unicode character as a numeric code, however, they cannot start with a dash or a digit.

#abc123 {color: red; background: black}

This and only this element can be identified as abc123

13. What is contextual selector?
Contextual selector is a selector that addresses specific occurrence of an element. It is a string of individual selectors separated by white space, a search pattern, where only the last element in the pattern is addressed providing it matches the specified context.

TD P CODE {color: red}

The element CODE will be displayed in red but only if it occurs in the context of the element P which must occur in the context of the element TD.

14. How do I have a background image that isn’t tiled?
Specify the background-repeat property as no-repeat. You can also use the background property as a shortcut for specifying multiple background-* properties at once. Here’s an example:

BODY {background: #fff url(watermark.jpg) no-repeat;}

15. What does \ABCD (and \ABCDE) mean?
CSS allows Unicode characters to be entered by number. For example, if a CLASS value in some Russian document contains Cyrillic letters EL PE (Unicode numbers 041B and 041F) and you want to write a style rule for that class, you can put that letter into the style sheet by writing:

.41B41F {font-style: italic;}
This works on all keyboards, so you don’t need a Cyrillic keyboard to write CLASS names in Russian or another language that uses that script.

The digits and letters after the backslash (\) are a hexadecimal number. Hexadecimal numbers are made from ordinary digits and the letters A to F (or a to f). Unicode numbers consist of four such digits.

If the number starts with a 0, you may omit it. The above could also be written as:

.\41B\41F {font-style: italic;}
But be careful if the next letter after the three digits is also a digit or a letter a to f! This is OK: .\41B-\41F, since the dash (-) cannot be mistaken for a hexadecimal digit, but .\41B9\41F is only two letters, not three.

Four digits is the maximum, however, so if you write:
.41B941F {font-style: italic;}

16. What are the advantages/disadvantages of the various style methods?
External Style Sheets
Advantages

* Can control styles for multiple documents at once
* Classes can be created for use on multiple HTML element types in many documents
* Selector and grouping methods can be used to apply styles under complex contexts

Disadvantages

* An extra download is required to import style information for each document
* The rendering of the document may be delayed until the external style sheet is loaded
* Becomes slightly unwieldy for small quantities of style definitions

Embedded Style Sheets
Advantages

* Classes can be created for use on multiple tag types in the document
* Selector and grouping methods can be used to apply styles under complex contexts
* No additional downloads necessary to receive style information

Disadvantages

* This method can not control styles for multiple documents at once

Inline Styles
Advantages

* Useful for small quantities of style definitions
* Can override other style specification methods at the local level so only exceptions need to be listed in conjunction with other style methods

Disadvantages

* Does not distance style information from content (a main goal of SGML/HTML)
* Can not control styles for multiple documents at once
* Author can not create or control classes of elements to control multiple element types within the document
* Selector grouping methods can not be used to create complex element addressing scenarios

17. What is inline style? How to link?
Inline style is the style attached to one specific element. The style is specified directly in the start tag as a value of the STYLE attribute and will apply exclusively to this specific element occurance.

18. What is imported Style Sheet? How to link?
Imported Style Sheet is a sheet that can be imported to (combined with) another sheet. This allows creating one main sheet containing declarations that apply to the whole site and partial sheets containing declarations that apply to specific elements (or documents) that may require additional styling. By importing partial sheets to the main sheet a number of sources can be combined into one.
To import a style sheet or style sheets include the @import notation or notations in the STYLE element. The @import notations must come before any other declaration. If more than one sheet is imported they will cascade in order they are imported – the last imported sheet will override the next last; the next last will override the second last, and so on. If the imported style is in conflict with the rules declared in the main sheet then it will be overridden.

.
19. What is alternate Style Sheet? How to link?
Alternate Style Sheet is a sheet defining an alternate style to be used in place of style(s) declared as persistent and/or preferred .
Persistent style is a default style that applies when style sheets are enabled but can disabled in favor of an alternate style, e.g.: <LINK REL=Stylesheet HREF=”style.css” TYPE=”text/css”>

Preferred style is a default style that applies automatically and is declared by setting the TITLE attribute to the LINK element. There can only be one preferred style, e.g.:  <LINK REL=Stylesheet HREF=”style2.css” TYPE=”text/css” TITLE=”appropriate style description”>

Alternate style gives an user the choice of selecting an alternative style – a very convenient way of specifying a media dependent style. Note: Each group of alternate styles must have unique TITLE, e.g.:

<LINK REL=”Alternate Stylesheet” HREF=”style3.css” TYPE=”text/css” TITLE=”appropriate style description” MEDIA=screen>
<LINK REL=”Alternate Stylesheet” HREF=”style4.css” TYPE=”text/css” TITLE=”appropriate style description” MEDIA=print>

20. How can you set a minimum width for IE?
To set a minimum width, the CSS property is ‘min-width’. This can be very useful and works well in good browsers. IE doesn’t understand ‘min-width’. However, it has a proprietary property called ‘expression’ which allows us to feed it javascript via a stylesheet. Below is how to set a (780px) minimum width for IE…


body {
width:expression(documentElement.clientWidth < 780 ? (documentElement.clientWidth == 0 ? (body.clientWidth < 780 ? “780px” : “auto”) : “780px”) : “auto” );
}

As the property is non-standard, it won’t validate with the W3C validator, so if we put it in the head like this (above) – in an IE conditional comment – the validator will ignore it and the page will get a clean bill of health.

21. How do I place text over an image?
To place text or image over an image you use the position property. The below exemple is supported by IE 4.0. All you have to do is adapt the units to your need.

“<div style=”position: relative; width: 200px; height: 100px”>
<div style=”position: absolute; top: 0; left: 0; width: 200px”>
<image>
</div>
<div style=”position: absolute; top: 20%; left: 20%; width: 200px”>
Text that nicely wraps
</div>
</div> “

22. What is attribute selector?

Attribute selector is a selector defined by 1) the attribute set to element(s), 2) the attribute and value(s), 3) the attribute and value parts:

1a) A[title] {text-decoration: underline}
All A elements containing the TITLE attribute will be underlined

1b) A[class=name] {text-decoration: underline}
The A elements classed as ‘name’ will be underlined

2) A[title="attribute element"] {text-decoration: underline}
The A elements containing the TITLE attribute with a value that is an exact match of the specified value, which in this example is ‘attribute element’, will be underlined

3) A[title~="attribute"] {text-decoration: underline}
The A elements containing the TITLE attribute with a value containing the specified word, which in this example is ‘attribute’, will be underlined

23. What is parent-child selector?
Parent-child selector is a selector representing the direct descendent of a parent element. Parent-child selectors are created by listing two or more tilde (~) separated selectors.

“BODY ~ P {background: red; color: white}

The P element will be declared the specified style only if it directly descends from the BODY element:
<BODY> <P>Red and white paragraph </P> </BODY>

BODY ~ P ~ EM {background: red; color: white}
The EM element will be declared the specified style only if it directly descends from the P element which in its turn directly descends from the BODY element:

<P> <EM>Red and white EM </EM> </P> </BODY>”

24. What are inline, block, parent, children, replaced and floating elements?

Inline elements

which do not have line breaks. Can occur in block elements or other inline elements, cannot contain block elements.
Inline elements in HTML 3.2; EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, TT, I, B, U, STRIKE, BIG, SMALL, SUB, SUP, A, IMG, APPLET, FONT, BASEFONT, BR, SCRIPT, MAP, INPUT, SELECT, TEXTAREA.

Inline elements in HTML 4.0; EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ABBR, ACRONYM, TT, I, B, BIG, SMALL, SUB, SUP, A, IMG, OBJECT, BR, SCRIPT, MAP, Q, SPAN, BDO, INPUT, SELECT, TEXTAREA, LABEL, BUTTON, (INS, DEL).

Inline elements in HTML 4.0 Transitional; EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ABBR, ACRONYM, TT, I, B, U, S, STRIKE, BIG, SMALL, SUB, SUP, A, IMG, APPLET, OBJECT, FONT, BASEFONT, BR, SCRIPT, MAP, Q, SPAN, BDO, IFRAME, INPUT, SELECT, TEXTAREA, LABEL, BUTTON, (INS, DEL).

Block elements

which do have line breaks. May occur in other block elements, cannot occur in inline elements, may contain both block and inline elements.

Block elements in HTML 3.2; H1, H2, H3, H4, H5, H6, ADDRESS, P, DL, DT, DD, UL, OL, DIR, MENU, LI, DIV, CENTER, BLOCKQUOTE, PRE, HR, ISINDEX, TABLE, FORM.

Block elements in HTML 4.0; P, H1, H2, H3, H4, H5, H6, UL, OL, PRE, DL, DIV, NOSCRIPT, BLOCKQUOTE, FORM, HR, TABLE, FIELDSET, ADDRESS, (INS, DEL).

Block elements in HTML 4.0 Transitional; P, H1, H2, H3, H4, H5, H6, UL, OL, DIR, MENU, PRE, DL, DIV, CENTER, NOSCRIPT, NOFRAMES, BLOCKQUOTE, FORM, ISINDEX, HR, TABLE, FIELDSET, ADDRESS, (INS, DEL).

Parents and children elements

which either contain (parents) or are in the content of (children) other elements, e.g.

” e.g. <P>text<STRONG>text</STRONG>text</P>.”  P is a parent of STRONG. STRONG is a child of P. If not specified otherwise, children will inherit parent’s properties.

Replaced
elements which content is replaced. For example content of the IMG element is replaced with an image, content of the INPUT element is replace with a field.
Floating
elements which follow the flow of a parent – inline elements.

25. What are pseudo-classes?
Pseudo-classes are fictional element types that do not exist in HTML. In CSS1 there is only one element type which can be classed this way, namely the A element (anchor). By creating three fictional types of the A element individual style can be attached to each class. These three fictional element types are: A as unvisited link, A as active link and A as visited link. Pseudo-classes are created by a colon followed by pseudo-class’s name. They can also be combined with normal classes, e.g.:

A:link {background: black; color: white}
A:active {background: black; color: red}
A:visited {background: transparent; color: black}

This anchor (or rather these anchors) will be displayed as declared above

A.foot:link {background: black; color: white}
A.foft:active {background; black: color: red}
A.foot:visited {background: transparent; color: black}

This anchor and all other anchors with CLASS foot will be displayed as declared above

26. What is CSS rule ‘at-rule’?
There are two types of CSS rules: ruleset and at-rule. At-rule is a rule that applies to the whole style sheet and not to a specific selector only (like in ruleset). They all begin with the @ symbol followed by a keyword made up of letters a-z, A-Z, digits 0-9, dashes and escaped characters, e.g. @import or @font-face.

27. What is ‘important’ declaration?
Important declaration is a declaration with increased weight. Declaration with increased weight will override declarations with normal weight. If both reader’s and author’s style sheet contain statements with important declarations the author’s declaration will override the reader’s.

BODY {background: white ! important; color: black}

In the example above the background property has increased weight while the color property has normal.

27 To what are partial URLs relative?
Partial URLs are relative to the source of the style sheet. The style sheet source can either be linked or embedded. To which source partial URLs are relative to depends on their occurrence.
If a partial URL occurs in a linked style sheet then it is relative to the linked style sheet. The URL of the linked style sheet is the URL of the directory where the sheet is kept.
If a partial URL occurs in an embedded style sheet then it is relative to the embedded style sheet. The URL of the embedded style sheet is the URL of the HTML document in which the sheet is embedded.
Note that Navigator 4.x treats partial URLs as being relative to the HTML document, regardless of the place where the partial URL occurs. This is a serious bug which forces most authors to use absolute URLs in their CSS.

28 What is the difference between ID and CLASS?
ID identifies and sets style to one and only one occurrence of an element while class can be attached to any number of elements. By singling out one occurrence of an element the unique value can be declared to said element.

CSS
#eva1 {background: red; color: white}
.eva2 {background: red; color: white}

“HTML – ID

<P ID=eva1>Paragraph 1 – ONLY THIS occurrence of the element P (or single occurrence of some other element) can be identified as eva1</P>
<P ID=eva1>Paragraph 2 – This occurrence of the element P CANNOT be identified as eva1</P>

HTML – CLASS
<P class=eva2>Paragraph 1 – This occurrence of the element P can be classified as eva2</P>
<P class=eva2>Paragraph 2 – And so can this, as well as occurrences of any other element, </P> “

29. What is shorthand property?
Shorthand property is a property made up of individual properties that have a common “addressee”. For example properties: font-weight, font-style, font-variant, font-size, font-family, refer to the font. To reduce the size of style sheets and also save some keystrokes as well as bandwidth they can all be specified as one shorthand property font, e.g.:

H1 {font-weight: bold;
font-style: italic;
font-variant: small-caps;
font-size: 160%;
font-family: serif}

can be all shorthanded to a space separated list:

H1 {font: bold italic small-caps 160% serif}

Note: To make things even simpler the line-height property can be specified together with the font-size property:

H1 {font: bold italic small-caps 160%/170% serif}

30. How does inheritance work?
HTML documents are structured hierarchically. There is an ancestor, the top level element, the HTML element, from which all other elements (children) are descended. As in any other family also children of the HTML family can inherit their parents, e.g. color or size.

By letting the children inherit their parents a default style can be created for top level elements and their children. (Note: not all properties can be inherited). The inheritance starts at the oldest ancestor and is passed on to its children and then their children and the children’s children and so on.

Inherited style can be overridden by declaring specific style to child element. For example if the EM element is not to inherit its parent P then own style must be declared to it. For example:

BODY {font-size: 10pt}
All text will be displayed in a 10 point font

BODY {font-size: 10pt}
H1 {font-size: 14pt} or H1 {font-size: 180%}

All text except for the level 1 headings will be displayed in a 10 point font. H1 will be displayed in a 14 point font (or in a font that is 80% larger than the one set to BODY). If the element H1 contains other elements, e.g. EM then the EM element will also be displayed in a 14 point font (or 180%) it will inherit the property of the parent H1. If the EM element is to be displayed in some other font then own font properties must be declared to it, e.g:

BODY {font-size: 10pt}
H1 {font-size: 14pt} or H1 {font-size: 180%}
EM {font-size: 15pt} or EM {font-size: 110%}

The EM element will be displayed in a 15 point font or will be 10% larger than H1. NOTE: EM is, in this example, inside H1 therefore will inherit H1’s properties and not BODY’s.

The above declaration will display all EM elements in 15 point font or font that is 10% larger than font declared to the parent element. If this specific font is to apply to EM elements but only if they are inside H1 and not every occurrence of EM then EM must take a form of a contextual selector.

H1 EM {font-size: 15pt} or H1 EM {font-size: 110%}

In the example above EM is a contextual selector. It will be displayed in specified font only if it will be found in the context of H1.

Not all properties are inherited. One such property is background. However, since it’s initial value is transparent the background of the parent element will shine through by default unless it is explicitly set.

31. What is Extensible Stylesheet Language (XSL)?
XSL is a proposed styling language for formatting XML (eXtensible Markup Language) documents. The proposal was submitted to the W3C by Microsoft, Inso, and ArborText.

32. How do you make a tooltip that appears on hover?
The most simple way is to use the ‘title’ attribute like this…

“HTML

<span title=”Example of the title attribute in use”>like this</span>

CSS
a.tooltip {
position:relative;
cursor:help;
}
a.tooltip span {
display:none;
position:absolute;
top:1.5em;
left:0;
width:15em;
padding:0 2px;
}
a.tooltip:hover {
display:inline;
}
a.tooltip:hover span {
display:block;
border:1px solid gray;
background-color:white;
}

HTML

<a class=”tooltip” href=”#n”>Karl Marx<span>-info goes here-</span></a>

Without this part… a.tooltip:hover {
display:inline;
}

..it won’t work in IE.

The “#n” in the link is to prevent the page from jumping to the top if the link is clicked. The “href” part is necessary as it won’t work in IE without it.”

var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.&#8221; : “http://www.&#8221;);
document.write(unescape(“%3Cscript src='” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));

try {
var pageTracker = _gat._getTracker(“UA-1855756-5″);
pageTracker._trackPageview();
} catch(err) {}

MNC php interview questions and answers

1) what is session_set_save_handler in PHP? session_set_save_handler() sets the user-level session storage functions which are used for storing and retrieving data associated with a session. This is most useful when a storage method other than those supplied by PHP sessions is preferred. i.e. Storing the session data in a local database.

2) what is garbage collection? default time ? refresh time? Garbage Collection is an automated part of PHP , If the Garbage Collection process runs, it then analyzes any files in the /tmp for any session files that have not been accessed in a certain amount of time and physically deletes them. arbage Collection process only runs in the default session save directory, which is /tmp. If you opt to save your sessions in a different directory, the Garbage Collection process will ignore it. the Garbage Collection process does not differentiate between which sessions belong to whom when run. This is especially important note on shared web servers. If the process is run, it deletes ALL files that have not been accessed in the directory.

There are 3 PHP.ini variables, which deal with the garbage collector: PHP ini  value

name                                          default

session.gc_maxlifetime     1440 seconds or 24 minutes

session.gc_probability      1

session.gc_divisor              100

3) PHP how to know user has read the email? Using Disposition-Notification-To: in mailheader we can get read receipt.

Add the possibility to define a read receipt when sending an email.

It’s quite straightforward, just edit email.php, and add this at vars definitions:

var $readReceipt = null;

And then, at ‘createHeader’ function add:

if (!empty($this->readReceipt)) { $this->__header .= ‘Disposition-Notification-To: ‘ . $this->__formatAddress($this->readReceipt) . $this->_newLine; }

4) Runtime library loading ? without default mysql support, how to run mysql with php?

dl — Loads a PHP extension at runtime int dl ( string $library )

Loads the PHP extension given by the parameter library .

Use extension_loaded() to test whether a given extension is already available or not. This works on both built-in extensions and dynamically loaded ones (either through php.ini or dl()).

bool extension_loaded ( string $name ) — Find out whether an extension is loaded

Warning :This function has been removed from some SAPI’s in PHP 5.3.

5) what is XML-RPC ? XML-RPC is a remote procedure call protocol which uses XML to encode its calls and HTTP as a transport mechanism. An XML-RPC message is an HTTP-POST request. The body of the request is in XML. A procedure executes on the server and the value it returns is also formatted in XML.

6) default session time ? default session time in PHP is 1440 seconds or 24 minutes.

7) default session save path ? Default session save path id temporary folder /tmp

8) What is the difference between htmlentities() and htmlspecialchars()?

htmlspecialchars() – Convert some special characters to HTML entities (Only the most widely used) htmlentities() – Convert ALL special characters to HTML entities

9) how to do session using DB?

bool session_set_save_handler ( callback $open , callback $close , callback $read , callback $write , callback $destroy , callback $gc ) using this function we can store sessions in DB.

PHP has a built-in ability to override its default session handling. The function session_set_save_handler() lets the programmer specify which functions should actually be called when it is time to read or write session information. by overriding the default functions using session_set_save_handler handle we can store session in Db like below example

class SessionManager {

var $life_time;

function SessionManager() {

// Read the maxlifetime setting from PHP $this->life_time = get_cfg_var(“session.gc_maxlifetime”);

// Register this object as the session handler session_set_save_handler( array( &$this, “open” ), array( &$this, “close” ), array( &$this, “read” ), array( &$this, “write”), array( &$this, “destroy”), array( &$this, “gc” ) );

}

function open( $save_path, $session_name ) {

global $sess_save_path;

$sess_save_path = $save_path;

// Don’t need to do anything. Just return TRUE.

return true;

}

function close() {

return true;

}

function read( $id ) {

// Set empty result $data = ”;

// Fetch session data from the selected database

$time = time();

$newid = mysql_real_escape_string($id); $sql = “SELECT `session_data` FROM `sessions` WHERE `session_id` = ‘$newid’ AND `expires` > $time”;

$rs = db_query($sql); $a = db_num_rows($rs);

if($a > 0) { $row = db_fetch_assoc($rs); $data = $row['session_data'];

}

return $data;

}

function write( $id, $data ) {

// Build query $time = time() + $this->life_time;

$newid = mysql_real_escape_string($id); $newdata = mysql_real_escape_string($data);

$sql = “REPLACE `sessions` (`session_id`,`session_data`,`expires`) VALUES(‘$newid’, ‘$newdata’, $time)”;

$rs = db_query($sql);

return TRUE;

}

function destroy( $id ) {

// Build query $newid = mysql_real_escape_string($id); $sql = “DELETE FROM `sessions` WHERE `session_id` = ‘$newid'”;

db_query($sql);

return TRUE;

}

function gc() {

// Garbage Collection

// Build DELETE query. Delete all records who have passed the expiration time $sql = ‘DELETE FROM `sessions` WHERE `expires` < UNIX_TIMESTAMP();';

db_query($sql);

// Always return TRUE return true;

}

}

10) how to track user logged out or not? when user is idle ? By checking the session variable exist or not while loading th page. As the session will exist longer as till browser closes.

The default behaviour for sessions is to keep a session open indefinitely and only to expire a session when the browser is closed. This behaviour can be changed in the php.ini file by altering the line session.cookie_lifetime = 0 to a value in seconds. If you wanted the session to finish in 5 minutes you would set this to session.cookie_lifetime = 300 and restart your httpd server.

11) how to track no of user logged in ? whenever a user logs in track the IP, userID etc..and store it in a DB with a active flag while log out or sesion expire make it inactive. At any time by counting the no: of active records we can get the no: of visitors.

12) in PHP for pdf which library used?

The PDF functions in PHP can create PDF files using the PDFlib library With version 6, PDFlib offers an object-oriented API for PHP 5 in addition to the function-oriented API for PHP 4. There is also the » Panda module.

FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.

FPDF requires no extension (except zlib to activate compression and GD for GIF support) and works with PHP4 and PHP5.

13) for image work which library?

You will need to compile PHP with the GD library of image functions for this to work. GD and PHP may also require other libraries, depending on which image formats you want to work with.

14) what is oops? encapsulation? abstract class? interface?

Object oriented programming language allows concepts such as modularity, encapsulation, polymorphism and inheritance.

Encapsulation passes the message without revealing the exact functional details of the class. It allows only the relevant information to the user without revealing the functional mechanism through which a particular class had functioned.

Abstract class is a template class that contains such things as variable declarations and methods, but cannot contain code for creating new instances. A class that contains one or more methods that are declared but not implemented and defined as abstract. Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract. Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class.

Interface: Interfaces are one type of class where all the methods are abstract. That means all the methods only declared but not defined. All the methods must be define by its implemented class.

15) what is design pattern? singleton pattern?

A design pattern is a general reusable solution to a commonly occurring problem in software design.

The Singleton design pattern allows many parts of a program to share a single resource without having to work out the details of the sharing themselves.

16) what are magic methods?

Magic methods are the members functions that is available to all the instance of class Magic methods always starts with “__”. Eg. __construct All magic methods needs to be declared as public To use magic method they should be defined within the class or program scope Various Magic Methods used in PHP 5 are: __construct() __destruct() __set() __get() __call() __toString() __sleep() __wakeup() __isset() __unset() __autoload() __clone()

17) what is magic quotes? Magic Quotes is a process that automagically escapes incoming data to the PHP script. It’s preferred to code with magic quotes off and to instead escape the data at runtime, as needed. This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.

18) diff b/w php4 & php5 ? In PHP5 1 Implementation of exceptions and exception handling

2. Type hinting which allows you to force the type of a specific argument as object, array or NULL

3. Overloading of methods through the __call function

4. Full constructors and destructors etc through a __constuctor and __destructor function

5. __autoload function for dynamically including certain include files depending on the class you are trying to create.

6 Finality : can now use the final keyword to indicate that a method cannot be overridden by a child. You can also declare an entire class as final which prevents it from having any children at all.

7 Interfaces & Abstract Classes

8 Passed by Reference : In PHP4, everything was passed by value, including objects. This has changed in PHP5 — all objects are now passed by reference.

9 An __clone method if you really want to duplicate an object

19) in php4 can you define a class? how to call class in php4? can you create object in php4?

yes you can define class and can call class by creating object of that class. but the diff b/w php4 & php5 is that in php4 everything was passed by value where as in php5 its by reference. And also any value change in reference object changes the actucal value of object also. And one more thing in introduction of __clone object in PHP5 for copying the object.

20) types of error? how to set error settings at run time?

here are three basic types of runtime errors in PHP:

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 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.

by using ini_set function.

21) what is cross site scripting? SQL injection?

Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications which allow code injection by malicious web users into the web pages viewed by other users. Examples of such code include HTML code and client-side scripts.

SQL injection is a code injection technique that exploits a security vulnerability occurring in the database layer of an application. The vulnerability is present when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements or user input is not strongly typed and thereby unexpectedly executed

22) what is outerjoin? inner join?

OUTER JOIN in SQL allows us to retrieve all values in a certain table regardless of whether these values are present in other tables

An inner join requires each record in the two joined tables to have a matching record. An inner join essentially combines the records from two tables (A and B) based on a given join-predicate.

23) what is URL rewriting?

Using URL rewriting we can convert dynamic URl to static URL Static URLs are known to be better than Dynamic URLs because of a number of reasons 1. Static URLs typically Rank better in Search Engines. 2. Search Engines are known to index the content of dynamic pages a lot slower compared to static pages. 3. Static URLs are always more friendlier looking to the End Users.

along with this we can use URL rewriting in adding variables [cookies] to the URL to handle the sessions.

24) what is the major php security hole? how to avoid?

1. Never include, require, or otherwise open a file with a filename based on user input, without thoroughly checking it first. 2. Be careful with eval() Placing user-inputted values into the eval() function can be extremely dangerous. You essentially give the malicious user the ability to execute any command he or she wishes! 3. Be careful when using register_globals = ON It was originally designed to make programming in PHP easier (and that it did), but misuse of it often led to security holes 4. Never run unescaped queries 5. For protected areas, use sessions or validate the login every time. 6. If you don’t want the file contents to be seen, give the file a .php extension.

25) whether PHP supports Microsoft SQL server ? The SQL Server Driver for PHP v1.0 is designed to enable reliable, scalable integration with SQL Server for PHP applications deployed on the Windows platform. The Driver for PHP is a PHP 5 extension that allows the reading and writing of SQL Server data from within PHP scripts. using MSSQL or ODBC modules we can access Microsoft SQL server.

26) what is MVC? why its been used? Model-view-controller (MVC) is an architectural pattern used in software engineering. Successful use of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other. In MVC, the model represents the information (the data) of the application; the view corresponds to elements of the user interface such as text, checkbox items, and so forth; and the controller manages the communication of data and the business rules used to manipulate the data to and from the model.

WHY ITS NEEDED IS 1 Modular separation of function 2 Easier to maintain 3 View-Controller separation means:

A — Tweaking design (HTML) without altering code B — Web design staff can modify UI without understanding code

27) what is framework? how it works? what is advantage?

In general, a framework is a real or conceptual structure intended to serve as a support or guide for the building of something that expands the structure into something useful. Advantages : Consistent Programming Model Direct Support for Security Simplified Development Efforts Easy Application Deployment and Maintenance

28) what is CURL?

CURL means Client URL Library

curl is a command line tool for transferring files with URL syntax, supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS and FILE. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos…), file transfer resume, proxy tunneling and a busload of other useful tricks.

CURL allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP’s ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.

29) HOW we can transfer files from one server to another server without web forms?

using CURL we can transfer files from one server to another server. ex:

Uploading file

<?php

/* http://localhost/upload.php: print_r($_POST); print_r($_FILES); */

$ch = curl_init();

$data = array(‘name’ => ‘Foo’, ‘file’ => ‘@/home/user/test.png’);

curl_setopt($ch, CURLOPT_URL, ‘http://localhost/upload.php&#8217;);

curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch); ?>

output:

Array ( [name] => Foo ) Array ( [file] => Array ( [name] => test.png
[type] => image/png [tmp_name] => /tmp/phpcpjNeQ [error] => 0 [size] => 279 )   )  

  30) using CSS can we have a scroll to table? 
No table won't support scrolling of its data. but we can do another workaround like placing a table
 in a DIV  layer and setting the DIV css property to overflow:auto will do the trick.  

  31) how to increase session time in PHP ? 
In php.ini by setting session.gc_maxlifetime and session.cookie_lifetime values
we can change the session time in PHP.   

 32) what is UI? What are the five primary user-interface components?  
 A user interface is a means for human beings to interact with computer-based "tools" and"messages".
One presumed goal is to make the user's experience productive, efficient, pleasing, and humane.
 The primary components of UIs are  a) metaphors (fundamental concepts communicated
 through words, images, sounds, etc.)
b) mental models (structure of data, functions, tasks, roles, jobs, and people in organizations of work
and/or play)
 c) navigation (the process of moving through the mental models)
d) interaction (all input-output sequences and means for conveying feedback)
 e) and appearance (visual, verbal, acoustic, etc.).
33) How can I set a cron and how can I execute it in Unix, Linux, and windows?

Cron is very simply a Linux module that allows you to run commands at predetermined times or intervals.

In Windows, it’s called Scheduled Tasks. The name Cron is in fact derived from the same word from which we get the word chronology, which means order of time.

The easiest way to use crontab is via the crontab command. # crontab This command ‘edits’ the crontab.

Upon employing this command, you will be able to enter the commands that you wish to run.

My version of Linux uses the text editor vi. You can find information on using vi here.

The syntax of this file is very important – if you get it wrong, your crontab will not function properly.

The syntax of the file should be as follows: minutes hours day_of_month month day_of_week command All the variables, with the exception of the command itself, are numerical constants.

In addition to an asterisk (*), which is a wildcard that allows any value, the ranges permitted for each field are as follows: Minutes: 0-59 Hours: 0-23 Day_of_month: 1-31 Month: 1-12 Weekday: 0-6 We can also include multiple values for each entry, simply by separating each value with a comma.

command can be any shell command and, as we will see momentarily, can also be used to execute a Web document such as a PHP file. So, if we want to run a script every Tuesday morning at 8:15 AM, our mycronjob file will contain the following content on a single line: 15 8 * * 2 /path/to/scriptname This all seems simple enough, right? Not so fast! If you try to run a PHP script in this manner, nothing will happen (barring very special configurations that have PHP compiled as an executable, as opposed to an Apache module).

The reason is that, in order for PHP to be parsed, it needs to be passed through Apache. In other words, the page needs to be called via a browser or other means of retrieving Web content.

For our purposes, I’ll assume that your server configuration includes wget, as is the case with most default configurations. To test your configuration, log in to shell.

If you’re using an RPM-based system (e.g. Redhat or Mandrake), type the following: # wget help If you are greeted with a wget package identification, it is installed in your system.

You could execute the PHP by invoking wget on the URL to the page, like so: # wget http://www.example.com/file.php Now, let’s go back to the mailstock.php file we created in the first part of this article.

We saved it in our document root, so it should be accessible via the Internet. Remember that we wanted it to run at 4PM Eastern time, and send you your precious closing bell report? Since I’m located in the Eastern timezone, we can go ahead and set up our crontab to use 4:00, but if you live elsewhere, you might have to compensate for the time difference when setting this value.

This is what my crontab will look like: 0 4 * * 1,2,3,4,5 wget http://www.example.com/mailstock.php

34)Difference b/w OOPS concept in php4 and PHP5 ?

version 4’s object-oriented functionality was rather hobbled. Although the very basic premises of objectoriented programming (OOP) were offered in version 4, several deficiencies existed, including: • An unorthodox object-referencing methodology • No means for setting the scope (public, private, protected, abstract) of fields and methods • No standard convention for naming constructors • Absence of object destructors • Lack of an object-cloning feature • Lack of support for interfaces

35) Difference b/w MyISAM and InnoDB in MySQL?

Ans:

  • The big difference between MySQL Table Type MyISAM and InnoDB is that InnoDB supports transaction
  • InnoDB supports some newer features: Transactions, row-level locking, foreign keys
  • InnoDB is for high volume, high performance
  • use MyISAM if they need speed and InnoDB for data integrity.
  • InnoDB has been designed for maximum performance when processing large data volumes
  • Even though MyISAM is faster than InnoDB
  • InnoDB supports transaction. You can commit and rollback with InnoDB but with MyISAM once you issue a command it’s done
  • MyISAM does not support foreign keys where as InnoDB supports
  • Fully integrated with MySQL Server, the InnoDB storage engine maintains its own buffer pool for caching data and indexes in main memory. InnoDB stores its tables and indexes in a tablespace, which may consist of several files (or raw disk partitions). This is different from, for example, MyISAM tables where each table is stored using separate files. InnoDB tables can be of any size even on operating systems where file size is limited to 2GB.
  • 36) how to set session tiem out at run time or how to extend the session timeout at runtime?

    Ans:

    Sometimes it is necessary to set the default timeout period for PHP. To find out what the default (file-based-sessions) session timeout value on the server is you can view it through a ini_get command:

    // Get the current Session Timeout Value
    $currentTimeoutInSecs = ini_get(’session.gc_maxlifetime’);

    Change the Session Timeout Value

    // Change the session timeout value to 30 minutes
    ini_set(’session.gc_maxlifetime’, 30*60);

    If you have changed the sessions to be placed inside a Database occasionally implementations will specify the expiry manually. You may need to check through the session management class and see if it is getting the session timeout value from the ini configuration or through a method parameter (with default). It may require a little hunting about.

    Aztecsoft php web developer interview questions and answers

    1) how to increase the web page performance ?

    1) Use lightweight templates
    2) Put Stylesheets at the Top
    3) Put Scripts at the Bottom
    4) Avoid CSS Expressions like As an example, the background color could be set to alternate every hour using CSS expressions.
    background-color: expression( (new Date()).getHours()%2 ? “#B8D4FF” : “#F08A00″ );

    5) Make JavaScript and CSS External
    6) Minify JavaScript and CSS : Minification is the practice of removing unnecessary characters from code to reduce its size thereby improving load times.

    7) Remove Duplicate Scripts
    8) Choose over @import
    9) Don’t Scale Images in HTML
    10) Make favicon.ico Small and Cacheable
    11) use Ajax, JSON, Jquery for fastening results

     

    2) $test=array( 0=>’one’ , 2=> ‘two’ , ‘3 ‘=>’three’ , ‘3a’=>5, ‘myindex’); print_r($test); what will be the output? 

    Array ( [0] => one [2] => two [3 ] => three [3a] => 5 [3] => myindex )

    3) what is output of this mysql function select substring_index(‘abc@123.com’,”@”,-1); 

    Ans:  123.com   explanation is below

    SUBSTRING_INDEX(str,delim,count)

    Returns the substring from string str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. SUBSTRING_INDEX() performs a case-sensitive match when searching for delim.

    mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2);
            -> 'www.mysql'
    mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', -2);
            -> 'mysql.com'

    This function is multi-byte safe.

     

    4) An employee table having columns  id {employee id} , name {employee name},  m_id {manager id }  , write a query to select employee and their manager names  ? 

     

    Main table    
    id name m_id
    1 John 2
    2 Greek Tor 1
    3 Alex John 1
    4 Mike tour 1
    5 Brain J 3
    6 Ronald 3
    7 Kin 4
    8 Herod 3
    9 Alen 2
    10 Ronne 1

    Ans:  INNER join SQL command is mostly used to join one table to it self. The biggest advantage of doing this is to get linking information from the same table. We will try to understand this with an example. The best example of INNER join will be employee table where we will keep the employee and its manager as a single record. This way by linking to the table it self we will generate a report displaying it as two linked tables. Each record will have one additional field storing the data of the manager by keeping the employee ID and we will use M_ID ( manager ID ) to link with main employee ID. This way we will link two virtual tables generated from one main table. 

    let us use inner join to create one report on who is the manager of which employee. Check this SQL 
    SELECT t1.id, t1.name as emp_name, t2.name as manager FROM emp as t1 INNER JOIN emp as t2 on t2.id = t1.m_id

    id emp_name manager
    1 John Greek Tor
    2 Greek Tor John
    3 Alex John John
    4 Mike tour John
    5 Brain J Alex John
    6 Ronald Alex John
    7 Kin Mike tour
    8 Herod Alex John
    9 Alen Greek Tor
    10 Ronne John

    for more :  To generate only the manager table used this SQL

    SELECT t1.id,t1.name as emp_name from emp as t1 INNER JOIN emp as t2 on t1.id=t2.m_id 

    Managers Table

     

     
    id emp_name
    2 Greek Tor
    1 John
    1 John
    1 John
    3 Alex John
    3 Alex John
    4 Mike tour
    3 Alex John
    2 Greek Tor
    1 John

     

    To generate only the employee table  used this SQL
    SELECT t1.id,t1.name as emp_name from emp as t1 INNER JOIN emp as t2 on t2.id=t1.m_id 

       
    id emp_name
    1 John
    2 Greek Tor
    3 Alex John
    4 Mike tour
    5 Brain J
    6 Ronald
    7 Kin
    8 Herod
    9 Alen
    10 Ronne

     

    use below dump for your reference 

    CREATE TABLE `emp` (
    `id` int(4) NOT NULL auto_increment,
    `name` varchar(25) NOT NULL default ”,
    `m_id` int(4) NOT NULL default ‘0’,
    UNIQUE KEY `id` (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;

    – 
    — Dumping data for table `emp`
    — 

    INSERT INTO `emp` VALUES (1, ‘John’, 2);
    INSERT INTO `emp` VALUES (2, ‘Greek Tor’, 1);
    INSERT INTO `emp` VALUES (3, ‘Alex John’, 1);
    INSERT INTO `emp` VALUES (4, ‘Mike tour’, 1);
    INSERT INTO `emp` VALUES (5, ‘Brain J’, 3);
    INSERT INTO `emp` VALUES (6, ‘Ronald’, 3);
    INSERT INTO `emp` VALUES (7, ‘Kin’, 4);
    INSERT INTO `emp` VALUES (8, ‘Herod’, 3);
    INSERT INTO `emp` VALUES (9, ‘Alen’, 2);
    INSERT INTO `emp` VALUES (10, ‘Ronne’, 1);


    5) write code to read the following file content “rag.txt”  and replace postgre SQL to MySQL and output the content ?

    The postgre SQL database has become the world’s most popular open source database because of its consistent fast performance, high reliability and ease of use. postgre SQL used on every continent — Yes, even Antarctica! — by individual Web developers as well as many of the world’s largest and fastest-growing organizations to save time and money powering their high-volume Web sites, business-critical systems and packaged software by postgre SQL.

    Ans:

     $str = file_get_contents(‘rag.txt’);

    $str = str_replace(‘postgre SQL’ ,’MySQL’, $str);

    echo $str;

     

    6) how we can destroy session cookie?

    Ans: we can use session_destroy() or  to destroy particular cookie set it to past time using  setcookie () function like  setcookie (“TestCookie”“”time() – 3600);

    7) True or False 

    a) session_destroy()  : destroys all of the data from session   TRUE

    b) session_unset() : frees all session variable  TRUE

    c) unset($_SESSION) deletes all session data   FALSE    “Do NOT unset the whole $_SESSION with unset($_SESSION) as this will disable the registering of session variables through the $_SESSION superglobal.”  

    8) $array = array( “hi”, “Hello World” , “what”, “Good Morning”);  write code to output the array contents havng more than one word ?
    Ans: 
        

    <? $array = array( “hi”, “Hello World” , “what”, “Good Morning”); 
    $count = sizeof($array);
    $i =0;
    while ($i < $count )
    {
    echo “<br> ***********<br>”;
    $exp = explode ( ” ” ,$array[$i] );
    if (count($exp) > 1)
    echo $array[$i] .” is having more than  one word in “. $i.” position of array  <br>”;
    $i++;
    }
    ?>
    9) what is the output of the below code 
    $sec_array = array(“red”, “green”, “blue”,”yellow”);
    array_splice( $sec_array , 1, -1);
    print_r($sec_array );   ? 

     

    Ans: Array ( [0] => red [1] => yellow )
    10) how we can get the second value from the last in an array ?
    Ans: 
    example  <? 
    $check = array ( “rag”, “shara”, “sharag”, “man”,”woman”,”child”, “human”);
    echo $check[count($check)-2];
    ?>

    11)  What is the maximum length of a URL?

    Microsoft states that the maximum length of a URL in Internet Explorer is 2,083 characters, with no more than 2,048 characters in the path portion of the URL

    Firefox, Safari , Opera  supports more than 100,000 characters.  but some times server like Apache, IIS may not support these longer URL’s. so better to keep it short URL.


    XML Interview Questions and Answers

    What is XML?

    The Extensible Markup Language (XML) is a general-purpose specification for creating custom markup languages.[1] It is classified as an extensible language, because it allows the user to define the mark-up elements. XML’s purpose is to aid information systems in sharing structured data.

    What is the version information in XML?
    The root element can be preceded by an optional XML declaration element stating what XML version is in use (normally 1.0); it might also contain character encoding and external dependencies information.

    What is ROOT element in XML?
    XML documents must contain one element that is the parent of all other elements. This element is called the root element.

    If XML does not have closing tag will it work?
    All XML Elements Must Have a Closing Tag otherwise it will produce error while accessing or parsing.

    Is XML case sensitive?
    yes it is. XML tags are case sensitive. With XML, the tag is different from the tag .

    Opening and closing tags must be written with the same case.

    What’s the difference between XML and HTML?
    On the surface, XML and HTML look similar. Both use tags (such as or ) and attributes (such as align=”left” or type=”personal”) to add information to the content. In fact, a carefully prepared HTML document can double as an XML document. The difference is that HTML is a well-defined set of elements and attributes. For example, the following is a well-formed XML document, but because it only uses tags that are defined in HTML, it’s also an HTML document:

    Message of the Day

    There is no message of the day.

    Try back tomorrow.

    On the other hand, HTML has somewhat looser rules than XML, so some HTML documents are not well-formed XML documents.

    Is XML meant to replace HTML?

    xml is a portable document structure, which is not really for presentation. XSL or CSS may replace html, but really xml is meant to be a storage medium. It is like asking if databases will replace html.

    The one aspect that makes this whole thing blurry is that html and now Xhtml is a subset of xml. It is just used to make documents render in browsers.

    Can you explain why your project needed XML?
    1. If we having huge datas to be transferred instead of sending all those datas as dataset you can opt xml.

    2. XML is easy to parse and it enables a faster accessing of datas.

    3. Case sensitiveness is an additional advantage in validating the authentication for the user.

    4. XML can be passed irrespective of OS, port and protocol.

    What is DTD (Document Type definition)?
    A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines the document structure with a list of legal elements and attributes.

    A DTD can be declared inline inside an XML document, or as an external reference

    Although XML allows you to invent as many different elements and attributes as you need, these elements and attributes, as well as their contents and the documents that contain them, must all follow certain rules in order to be well-formed. If a document is not well-formed, any attempts to read it or render it will fail.

    What is a valid XML?
    XML that meets the constraints defined by its Document Type Declaration.

    What is CDATA section in XML?
    CDATA Sections are used to escape blocks of text containing characters which would otherwise be recognized as markup. All tags and entity references are ignored by an XML processor that treats them just like any character data. CDATA blocks have been provided as a convenience measure when you want to include large blocks of special characters as character data, but you do not want to have to use entity references all the time

    What is XSL?

    Extensible Style Language is a style sheet language aimed at activities such as rearranging the document that are not supported by CSS, though XSL and CSS share the same underlying concepts. XSL can be used to style XML documents u sing sets of rules and definitions of actions to be applied. XSL is a specification from the W3C.

    What is Element and attributes in XML?
    The basic building blocks of XML Schemas are elements and attributes. Data types define the valid content that elements and attributes contain. When you create XML Schemas, you define the individual elements and attributes and assign valid types to them. Elements describe data, whereas attributes are like properties of an element, in that they provide further definition about the element the way that properties describe characteristics of objects and classes.
    An element describes the data that it contains. Elements can also contain other elements and attributes.
    An attribute is a named simple-type definition that cannot contain other elements. Attributes can also be assigned an optional default value and they must appear at the bottom of complex-type definitions. Additionally, if multiple attributes are declared, they may occur in any order.

    What are the standard ways of parsing XML document?

    DOM and SAX parsers are the standard ways for parsing XML document.

    In What scenarios will you use a DOM parser and SAX parser?
    In some scenarios, SAX is easily the better choice for quick, less-intensive parsing and processing. In others, the DOM provides an easy-to-use, clean interface to data in a desirable format. You, the developer, must always analyze your application and its purpose to make the correct decision as to which method to use, or how to use both in concert.

    What is XSLT?
    Extensible Stylesheet Language Transformations. A programming language specialized for the transformation of XML documents.

    Define XPATH?
    A query language used to identify a set of nodes within a XML document. Originally defined to be used with XSLT, it is also used by XPointer and a simple subset is used in the xs:key, xs:keyref, and xs:unique W3C XML Schema elements. The XQuery specification will be a superset of the second version of XPath. This version will use type information provided by W3C XML Schema

    What is an XMLReader Class?
    Represents a reader that provides fast, non-cached, forward-only access to XML data.
    XmlReader provides forward-only, read-only access to a stream of XML data. The XmlReader class conforms to the W3C Extensible Markup Language (XML) 1.0 and the Namespaces in XML recommendations.

    What is XMLTextReader?

    The XmlTextReader class requires fast access to XML data. It does not require reading the entire document into memory via the Document Object Model (DOM). The class is derived from the XmlReader class and implements all the methods defined in the XmlReader class. The following are the functions of the XmlTextReader class:

    * It enforces rules of a well-formed XML document.

    * It does not provide any data validation in a document.

    * It checks the Document Type Definition (DTD) and DocumentType nodes for their well-formed structure, but does not validate these nodes by using the DTD.

    How do we access attributes using “XmlReader”?
    The XmlReader class provides various methods and properties for reading attributes. Attributes are most commonly found on elements. However, they are also allowed on XML declaration and document type nodes.

    When positioned on an element node, the MoveToAttribute methods enable you to go through the attribute list of the element. After MoveToAttribute has been called, the node properties—such as Name, NamespaceURI, Prefix, and so on—reflect the properties of that attribute, and not the containing element it belongs to.

    What does XmlValidatingReader class do?
    Represents a reader that provides document type definition (DTD), XML-Data Reduced (XDR) schema, and XML Schema definition language (XSD) validation.

    XmlValidatingReader implements the XmlReader class and provides support for data validation. Use the Schemas property to have the reader validate by using schema files that are cached in an XmlSchemaCollection. The ValidationType property specifies what type of validation the reader should perform. Setting the property to ValidationType.None creates a non-validating reader.

    Follow

    Get every new post delivered to your Inbox.

    Join 65 other followers