> 2012 ~ Online tutorial

foreach statement in php

foreach Statement:

The foreach statement is used to loop through arrays.
For every loop, the value of the current array element is assigned to $value (and the array pointer is moved by one) so on the next loop, you'll be looking at the next element.
Syntax
foreach (array as value)
{
code to be executed;
}

Example

<html>
<body>
<?php
$arr=array("one", "two", "three");
foreach ($arr as $value)
{
echo "Value: " . $value . "
";
}
?>
</body>
</html>

Output;

one
two 
three

for Statement in php

for Statement
The for statement is used when you know how many times you want to execute a statement or a list of statements.
Syntax
for (initialization; condition; increment)
{
code to be executed;
}

Note:

The for statement has three parameters. The first parameter initializes variables, the second parameter holds the condition, and the third parameter contains the increments required to implement the loop. If more than one variable is included in the initialization or the increment parameter, they should be separated by commas. The condition must evaluate to true or false.
Example

<html>
<body>
<?php
for ($i=1; $i<=5; $i++)
 {
 echo "Hello World!";
}
?>

≤html>
Output
Hello World
Hello World
Hello World
Hello World
Hello World

do...while Statement in php

The do...while Statement
The do...while statement will execute a block of code at least once - it then will repeat the loop as long as a condition is true.
Syntax

do
{
code to be executed;
}
while (condition);



Example
The following example will increment the value of i at least once, and it will continue incrementing
the variable i as long as it has a value of less than 5:



<html>
<body>
<?php
$i=0;
do
{
$i++;
echo "The number is " . $i . " ";
}
while ($i<5)
</body>
</html>

while statement in php

The while Statement
The while statement will execute a block of code if and as long as a condition is true.
Syntax
while (condition)
code to be executed;
Example
The following example demonstrates a loop that will continue to run as long as the variable i is
less than, or equal to 5. i will increase by 1 each time the loop runs:

<html>
<body>
<?php
$i=1;
while($i<=5)
{
echo "The number is " . $i . "
$i++;
}
?>

Looping in php

PHP Looping:

Looping statements in PHP are used to execute the same block of code a specified
number of times.
Looping Very often when you write code, you want the same block of code to run a number of times. You
can use looping statements in your code to perform this.

In PHP we have the following looping statements:

• while - loops through a block of code if and as long as a specified condition is true

• do...while - loops through a block of code once, and then repeats the loop as long as a
special condition is true

• for - loops through a block of code a specified number of times

• foreach - loops through a block of code for each element in an array

Multidimensional Arrays in php

Multidimensional Arrays
In a multidimensional array, each element in the main array can also be an array. And each
element in the sub-array can be an array, and so on.
Example
In this example we create a multidimensional array, with automatically assigned ID keys:

$families = array
(
"Griffin"=>array
(
"Peter",
"Lois",
"Megan"
),
"Quagmire"=>array
(
"Glenn"
),
"Brown"=>array
(
"Cleveland",
"Loretta",
"Junior"
)
);

The array above would look like this if written to the output:


Array
(
[Griffin] => Array
(
[0] => Peter
[1] => Lois
[2] => Megan
)
[Quagmire] => Array
(
[0] => Glenn
)
[Brown] => Array
(
[0] => Cleveland
[1] => Loretta
[2] => Junior
)
)

Associative Array in php

Associative Arrays
An associative array, each ID key is associated with a value.
When storing data about specific named values, a numerical array is not always the best way to
do it.
With associative arrays we can use the values as keys and assign values to them.
Example 1
In this example we use an array to assign ages to the different persons:
$ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34);
Example 2
This example is the same as example 1, but shows a different way of creating the array:
>

$ages['Peter'] = "32";
$ages['Quagmire'] = "30";
$ages['Joe'] = "34";

The ID keys can be used in a script:

<
?php
$ages['Peter'] = "32";
$ages['Quagmire'] = "30";
$ages['Joe'] = "34";
echo "Peter is " . $ages['Peter'] . " years old.";
?>
The code above will output:
Peter is 32 years old.

Numeric array in php

Numeric Arrays
A numeric array stores each element with a numeric ID key.
There are different ways to create a numeric array.
Example 1
In this example the ID key is automatically assigned: PDF by Hans Home Collection

$names = array("Peter","Quagmire","Joe");

Example 2
In this example we assign the ID key manually:



$names[0] = "Peter";
$names[1] = "Quagmire";
$names[2] = "Joe";

The ID keys can be used in a script:


<?php
$names[0] = "Peter";
$names[1] = "Quagmire";
$names[2] = "Joe";
echo $names[1] . " and " . $names[2] .
" are ". $names[0] . "'s neighbors";
?>
The code above will output:
Quagmire and Joe are Peter's neighbors

php array

PHP Arrays
An array stores multiple values in one single variable.What is an Array?
A variable is a storage area holding a number or text. The problem is, a variable will hold only one value.
An array is a special variable, which can store multiple values in one single variable.

If you have a list of items (a list of car names, for example), storing the cars in single variables could
look like this:

$cars1="Saab";
$cars2="Volvo";
$cars3="BMW";
However, what if you want to loop through the cars and find a specific one? And what if you had not 3 cars, but 300?
The best solution here is to use an array!An array can hold all your variable values under a single name. And you can access the values by referring to the array name.

Type of Array
Numeric Array
Multidimensional Arrays
Associative array
Function in Array
list()
array_sum()
array_unique()
asort()
array_values()
array_push()
count()
in_array()
ksort()

Strpos() function in php

strpos() function
The strpos() function is used to search for character within a string.
If a match is found, this function will return the position of the first match.
If no match is found, it will return FALSE.
Let's see if we can find the string "world" in our string:

< ?php
echo strpos("Hello world!","world");
? >

The output of the code above will be:

6

The position of the string "world" in our string is position 6. The reason that it is 6 (and not 7), is that

strlen() function in php

strlen() function
The strlen() function is used to return the length of a string.
Let's find the length of a string:

<?php
echo strlen("Hello world!");
? >

The output of the code above will be:
12
The length of a string is often used in loops or other functions, when it is important to know when the
string ends. (i.e. in a loop, we would want to stop the loop after the last character in the string).

Concatenation operator in php

The Concatenation Operator
There is only one string operator in PHP.
The concatenation operator (.) is used to put two string values together.
To concatenate two string variables together, use the concatenation operator:

Example

?php
$txt1="Hello World!";
$txt2="What a nice day!";
echo $txt1 . " " . $txt2;
?

The output of the code above will be:
Hello World! What a nice day! 

If we look at the code above you see that we used the concatenation operator two times. This is because
we had to insert a third string (a space character), to separate the two strings.

String in php

PHP String Variables
A string variable is used to store and manipulate text.
String Variables in PHP
String variables are used for values that contains characters.
In this chapter we are going to look at the most common functions and operators used to manipulate
strings in PHP.
After we create a string we can manipulate it. A string can be used directly in a function or it can be stored in a variable.
Below, the PHP script assigns the text "Hello World" to a string variable called $txt:




?php
$txt="Hello World";
echo $txt;
?

The output of the code above will be:
Hello World
Now, lets try to use some different functions and operators to manipulate the string.

Function in String
strops()
strlen
Chunksplit()
addcslashes() and backcslahes()
chop()
chr()
implode()
nl2br()
strrev()
strlen()
substr()
trim()

String Operators in php


 String Operators
As we have already seen in the Echo Lesson, the period "." is used to add two strings together, or more
technically, the period is the concatenation operator for strings. 


PHP Code:


$a_string = "Hello";
$another_string = " Billy";
$new_string = $a_string . $another_string;
echo $new_string . "!";

Display:


Hello Billy!  

Comparison Operators in php


Comparison Operators
Comparisons are used to check the relationship between variables and/or values. If you would like to see
a simple example of a comparison operator in action, check out our If Statement Lesson. Comparison operators are used inside conditional statements and evaluate to either true or false. Here are the most important comparison operators of PHP. 

Assume: $x = 4 and $y = 5; 


Operator English ExampleResult
== Equal To $x == $y false
!= Not Equal To $x != $y true
< Less Than $x < $y true
>Greater Than $x > $y false
<= Less Than and Equal To $x <= $y true
>= Greater Than and Equal To $x >= $y false


Assignment Operators in php


Assignment Operators
Assignment operators are used to set a variable equal to a value or set a variable to another variable's
value. Such an assignment of value is done with the "=", or equal character.

Example

•  $my_var = 4; 
•  $another_var = $my_var  

Now both $my_var and $another_var contain the value 4. Assignments can also be used in conjunction
with arithmetic operators.
  

Php operator

Operators in PHP

In all programming languages, operators are used to manipulate or perform operations on variables and
values. You have already seen the string concatenation operator "." in the Echo Lesson and the assignment
operator "=" in pretty much every PHP example so far.
  There are many operators used in PHP, so we have separated them into the following categories to make
it easier to learn them all.
Concatenation operator
Assignment Operators
Arithmetic Operators
String operator

Arithmetic Operators in php

Using Arithmetic Operators
To perform mathematical operations on variables, use the standard arithmetic
operators, as illustrated in the following example:

<?php

// define variables

$num1 = 101;

$num2 = 5;

// add

$sum = $num1 + $num2;

// subtract

$diff = $num1 - $num2;

// multiply

$product = $num1 * $num2;
// divide

$quotient = $num1 / $num2;

// modulus

$remainder = $num1 % $num2;

?>



To perform an arithmetic operation simultaneously with an assignment, use the

two operators together. The following two code snippets are equivalent:


<?php

$a = $a + 10;

?>

<?php

$a += 10;

?>


Operator What It Does
= Assignment
+ Addition
- Subtraction
* Multiplication
/ Division; returns quotient
% Division; returns modulus
&& Logical AND
|| Logical OR
xor Logical XOR
! Logical NOT
++ Addition by 1

Data types in PHP


Understanding Simple Data Types


Every language has different types of variables—and PHP has no shortage of choices.
The language supports a wide variety of data types, including simple numeric,
character, string, and Boolean types, and more complex arrays and objects.

Data Type Description Example
Integer An integer is a plain-vanilla

number like 75, -95, 2000,

or 1.
$age = 99;
Boolean The simplest variable type

in PHP, a Boolean variable

simply specifies a true or

false value
$auth = true;
Floating-point A floating-point number

is typically a fractional

number such as 12.5

or 3.149391239129.

Floating point numbers may

be specified using either

decimal or scientific notation.
$temperature = 56.89;
String A string is a sequence of

characters, like 'hello' or

'abracadabra'. String

values may be enclosed in

either double quotes ("") or

single quotes ('').
$name = 'Harry';
In many languages, it’s essential to specify the variable type before using it; for

example, a variable may need to be specified as type integer or type array.

Give PHP credit for a little intelligence, though—the language can automagically

determine variable type by the context in which it is being used.

Writing Statements and Comments in php


Writing Statements and Comments


As you can see from the previous example, a PHP script consists of one or more
statements, with each statement ending in a semicolon. Blank lines within the
script are ignored by the parser. Everything outside the tags is also ignored by the
parser, and returned as is; only the code between the tags is read and executed.

TIPS

If you’re in a hurry, you can omit the semicolon on the last line of a PHP
block, because the closing ?> includes an implicit semicolon. Therefore,
the line is<?php echo 'Hello' ?>  perfectly valid PHP code.
This is the only time a PHP statement not ending in a semicolon is still
considered valid.
For greater readability, you should add comments to your PHP code, as I did in
the previous example. To do this, simply use one of the Comments styles listed here:


<?php


// this is a single-line comment

# so is this

/* and this is a

multiline

comment */

?>

Feature in PHP

Features

As a programming language for the Web, PHP is hard to ignore. Clean syntax,
object-oriented fundamentals, an extensible architecture that encourages innovation,
support for both current and upcoming technologies and protocols, and excellent
database integration are just some of the reasons for the popularity it currently
enjoys in the developer community.

Simplicity:

                 Because PHP uses a consistent and logical syntax, and because it comes with
a clearly written manual, even novices find it easy to learn. In fact, the quickest
way to learn PHP is to step through the manual’s introductory tutorial, and then
start looking at code samples off the Web. Within a few hours, you’ll have learned
the basics and will be confident enough to begin writing your own scripts. This
adherence to the KISS (Keep It Simple, Stupid) principle has made PHP popular
as a prototyping and rapid application development tool for web applications. PHP
can even access C libraries and take advantage of program code written for this
language, and the language is renowned for the tremendous flexibility it allows
programmers in accomplishing specific tasks.

Portability:

With programming languages, portability—the ease with which a program can
be made to work on different platforms—is an important factor. PHP users have
little to fear here, because cross-platform development has been an important
design goal of PHP since PHP 3.0. Today, PHP is available for a wide variety of
platforms, including UNIX, Microsoft Windows, Mac OS, and OS/2. Additionally,
because PHP code is interpreted and not compiled, PHP scripts written on one
platform usually work as is on any other platform for which an interpreter exists.
This means that developers can code on Windows and deploy on UNIX without
any major difficulties.

Speed:

          Out of the box, PHP scripts run faster than most other scripting languages, with
numerous independent benchmarks putting the language ahead of competing
alternatives like JSP, ASP.NET, and Perl. When PHP 4.0 was first released, it
raised the performance bar with its completely new parsing engine. PHP 5.0
improves performance even further through the use of an optimized memory
manager, and the use of object handles that reduce memory consumption and
help applications run faster.


Open Source:

         Possibly the best thing about PHP is that it’s free—its source code is freely
available on the Web, and developers can install and use it without paying licensing
fees or investing in expensive hardware or software. Using PHP can thus significantly
reduce the development costs of a software application, without compromising on
either reliability or performance. The open-source approach also ensures faster bug
fixes and quicker integration of new technologies into the core language, simply
due to the much larger base of involved developers.

Extensible:

Keeping future growth in mind, PHP’s creators built an extensible architecture
that enables developers to easily add support for new technologies to the language
through modular extensions. This extensibility keeps PHP fresh and always at
the cutting edge of new technology. To illustrate this, consider what PHP lets you
do through its add-on modules: dynamically create image, PDF, and SWF files;
connect to IMAP and POP3 servers; interface with MySQL, Oracle, PostgreSQL

,and SQLite databases; handle electronic payments; parse XML documents; and
execute Perl, Java, and COM code through a PHP script. And as if all that wasn’t
enough, there’s also an online repository of free PHP classes called PEAR, the
PHP Extension and Application Repository, which provides a source of reusable,
bug-free PHP components.


BUY IT:

Title Tag Optimization

1)Indicate page titles by using title tags

A title tag tells both users and search engines what the topic of a particular page is. The <title> tag should be placed within the <head> tag of the HTML document


(1). Ideally, you should create a unique title for each page on your site.

<html>
<head>
<title>Brandon's Baseball Cards - Buy Cards, Baseball News, Card Prices</title>
<meta name="description=" content="Brandon's Baseball Cards provides a
large selection of vintage and modern baseball cards for sale. We also offer
daily baseball news and events in">
</head>
<body>

1) The title of the homepage for our baseball card site, which lists the business
name and three main focus areas.


2)Page title contents are displayed in search results

If your document appears in a search results page, the contents of the title tag will usually appear in the first line of the results (if you're unfamiliar with the different parts of a Google search result, you might want to check out the anatomy of a search result video by Google engineer Matt Cutts, and this helpful diagram of a Google search results page). Words in the title are bolded if they appear in the user's search query.This can help users recognize if the page is likely to be relevant to their search

3)The title for your homepage can list the name of your website/business and could include other bits of important information like the physical location of the business or maybe a few of its main focuses or offerings .

3)Be mindful of length

70 characters is the maximum amount that will display in the search
title tag has been cut off), and sticking to this limit is generally wise.
keyword phrase) and having them in the title tag is essential to
ranking, it may be advisable to go longer.



4)Place important keywords close to the front
5)Leverage branding



Using keywords in the title tag means that search engines will bold these search terms this  has performed a query with those terms. This helps garner a
greater visibility and a higher click-through rate.

6)Consider readability and emotional impact
The closer to the start of the title tag your keywords are, the more
testing and experience.
At SEOmoz, we love to start every title tag with a brand name
mention, as these help to increase brand awareness, and create a
higher click-through rate for people who like and are familiar with a
brand. Many SEO firms recommend using the brand name at the end
of a title tag instead, and there are times when this can be a better
site) and how strong the brand is.

Creating a compelling title tag will pull in more visits from the search
important to not only think about optimization and keyword usage,
interaction with your brand and should convey the most positive
impression possible.

SEO Tutorial for beginner

seo interview questions

1 ) What is Search Engines ?


 Search Engine are Key of Finding Specific Information on the vast expanse of the World Wide Web

2 ) How to achieve Google Page Rank ? 

 Google Page Rank Largely Dependent on Links so more the Backlinks you have the more is your page rank it also affected by the rank of page linked to you.
One other thing that you should consider is that the older your website is, the more trusted and favorable it is to Google. A website with plenty of pages, a lot of incoming links, and also plenty of internal links to other pages within your website–all these are well regarded by Google.

3 ) What are Meta Tags .

They are keywords that are Hidden in the Code of your Page. Search Engine can see and Viewed them but generally your visitor can’t.

4 ) What is Value of Title Tags used in Website ?

Title is Vital to your SEO Efforts. Each Page need to have a Unique Title that accurately describe the content containing in that pages.
Reason : Page title is important because this is what will be displayed in the result section of search

 5 ) What is Site Map ?

 Search Engines need a Site Map to Index your site properly. This will them what content you have and How you organized that content. By using site map you make your site more search engine friendly and increasing the chance of frequent indexing.

6 ) Why we use Robots.txt File ?

Robots file is used when you have duplicate content that you don’t want to be indexed, or you want to create a no follow rule for specific areas of your Websites, you need one of these files

7 ) How Keywords are Choose for Optimization ?

The Success of Choosing Keywords is to pick the Keywords that are Popular, related to your content and effective. Avoid the practice of overusing or over stuffing your keywords. Stick to density of 3-4% per page on your top keywords for the best effect.

8 ) What is Black Hat SEO ?

 Race Among websites to attain High Ranking has brought about a Number of methods and technique used to achieve this goals. These Methods can be characterized into two Groups depend on there acceptability to search engines.

White Hat SEO – SEO Methods that conform to search engine Guidelines are White Hat

Black Hat SEO – SEO Methods those are viewed as less acceptable are called Black Hat

9 ) What is Cloaking ?

Cloaking involves having two separated pages one to show to google bot and other to show to your sites visitors

10 ) What is Blog Flipping ?

Practice of selling Blog to other one after it attains popularity and traffic.

11) What is PPC 

PPC method of Online Advertisement where you pay per click when visitor type your ad displayed on search engine

12)What is bounce Rate?

Bounce Rate is the percentage of single-page visits from user.







What is SEO

What SEO Is

Search Engine Optimization refers to the collection of techniques and practices that allow a site to get more traffic from search engines (Google, Yahoo, Microsoft). SEO can be divided into two main areas: off-page SEO (work that takes place separate from the website) and on-page SEO (website changes to make your website rank better). This tutorial will cover both areas in detail! Remember, a website is not fully optimized for search engines unless it employs both on and off-page SEO.

What SEO Is Not

SEO is not purchasing the number #1 sponsored link through Google Adwords and proclaiming that you have a #1 ranking on Google. Purchasing paid placements on search engines is a type of Search Engine Marketing (SEM), and is not covered in this tutorial.
SEO is not ranking #1 for your company's name. If you're reading this tutorial, you probably already know that ranking for popular terms is darn near impossible, but specific terms, such as a company name, is a freebie. The search engines usually are smart enough to award you that rank by default (unless you are being penalized).

Who Uses SEO

If a website is currently ranked #10 on Google for the search phrase, "how to make egg rolls," but wants to rise to #1, this websites needs to consider SEO. Because search engines have become more and more popular on the web, nearly anyone trying to get seen on the web can benefit from a little SEO loving.

Keyword Research

Before you can start optimizing your site for the search engines, you must first know which terms you want to target. A good start would be to choose 3 or 4 keywords you would like your website to rank well for. With these keywords in your mind you can then set a goal to rank in the top 10 results on Google for each of them (we refer to Google because if you can rank well there, you'll rank well on the other search engines). These keywords can be either broad or specific, but you'll want to study our list of pros and cons of each before choosing.



Broad Keywords
A broad keyword is one that many people search for, because they may only have a vague idea of what they're looking for. Broad keywords tend to be very short and aren't very specific (e.g. "shoes" or "sports"). These keywords are difficult to rank #1 for because so many other websites might have an article or two that mention shoes. However, if you can rank well for a broad keyword, you will be receiving a great deal of traffic.

Summary:

Hard to rank for, but worth it in the long run. We recommend that beginners only choose a broad keyword if their industries are not very competitive.

Specific Keywords
A specific keyword is something that contains many adjectives or words that make the search very targeted. The people doing these types of searches know exactly what they want (e.g. "used black high heel shoes"). These keywords are much less competitive and are easier to rank for on search engines. The downside is that they receive a great deal less volume of searches per month. In terms of traffic, you will need to have several #1 rankings for specific keywords to equal one #1 ranking broad keyword.
Summary: Easier to rank for and it's highly targeted traffic. The only downside is that the number of visitors you will receive is relatively low.

Unique or Branded Keywords

These are the words that are specific to only your company. They are one of the most easiest ways to get traffic. However, some companies will release a new product, with a unique name, and then forget to optimize for that keyword on their website. Their SEO savvy competitors can then pick up the slack and take over the top rankings for these terms. If you have a popular brand or product, make sure that you have optimized for these freebie keywords.

Keyword Research Tools

Keyword research tools are 2 parts voodoo magic and 1 part hard statistic. This is partly due to Google not releasing actual numbers and partly due to overeager SEO Tool developers trying to sell their products. Because there is such a sizable uncertainty in all keyword research tools, it is best to use as many different sources as you can,. Even with multiple sources, you should only take the information you gather as a recommendation, rather than a fact.

Yahoo has been releasing their keyword search information for years, and many tools are based off of this specific data. We've collected a wide variety of helpful tools that will give you a general idea of which keywords you should target when making and optimizing your websites.
Picking a Short List

To put the optimizing tactics that we teach to good use, we recommend that you try to target no more than 2 or 3 keyword phrases per page. A common mistake by many SEO beginners is to stuff 500 different keywords on one page and wait for the #1 rankings to roll in. That might have worked 10 years ago, but the algorithms that search engines use these days are much more sophisticated and are not tricked by this. That's why it's best to start small, and be concise with the keywords that you choose. New sites in particular will find it nearly impossible to rank well for many keyword phrases upon first starting out.