Sunday, April 1, 2012

Cookies In PHP



A cookie is a small text file in which a website can store different information. Cookies are saved on the user's hard drive and not on the server.
Most cookies expire (delete themselves) after a predetermined time period, which can range from one minute to several years. But the user can also identify and delete any cookies on his/her computer.
Most browsers, such as Microsoft Internet Explorer, Mozilla Firefox and Google Chrome, can be configured to let the user choose whether or not he/she will accept a cookie. But then, why not just say no to all cookies? It is possible. But many websites would not work as intended without cookies, since cookies in many contexts are used to improve the usability and functionality of the website.

How is information stored in a cookie?

It's easy to set or modify a cookie in PHP with setcookie. In the first example, we will create a cookie and set the value.
First, you need a name for the cookie. In this example we will use the name "HTMLTest". Next, you set the value of the cookie like this:

 <?php 

 // Setting the cookie
 setcookie("HTMLTest", "This is a test cookie");   

 ?>

 
By default, a cookie is kept untill the browser is closed, but it can easily be modified by adding another parameter setting the expiry time:


 <?php 

 // Setting the cookie
 setcookie("Name", "C. Wing, time()+3600);   
 setcookie("Interests", "plane spotting", time()+3600); 
 
 ?>



"Time()+3600" specified that the cookie should expire in 3600 seconds (60 minutes) from now.
In the example above, we stored information about a user's name and interests. This information can, for example, be useful to target the website specifically for the individual visitor.

How do you retrieve the value of a cookie?

To get the value of the cookie, $_COOKIE is used. For example, if we need the information from the example above, we do it like this:


 <?php 

 // Retrieve values from the cookie
 $strName = $_COOKIE["Name"];   
 $strInterest = $_COOKIE["Interest"];
  
 // Write to the client
 echo "<p>" . strName . "</p>"   
 echo "<p>Your interest is . " strInterest . "</p>"
 
 ?>

Who can read the cookie?

By default, a cookie can be read at the same second-level domain (e.g.  prog-teach.blogspot.com ) as it was created. But by using the parameters domain and path, you can put further restrictions on the cookie using the following syntax:


setcookie(name, value, expiration time, path, domain);

 
Let us look at an example:
 
 <?php
 
 // Setting the cookie: name, value, expiration time, path, domain
 setcookie("Name", "C. Wing", time()+60*60*24*365, "/tutorials/php/", "www.prog-teach.blogspot.com");   
 ?>
In the example above, we set a cookie called "Name" with the value "C. Wing." The cookie expires after one year (60 seconds * 60 minutes * 24 hours * 365 days) and can be read only by sites located in the directory "/tutorials/php/" on the (sub-)domain .

Example of a cookie

We can try to save a sample cookie on your computer and then see how it looks.
The following code sets the cookie:


 <?php 

 // Setting the cookie
 setcookie("HTMLTest", "This text is in a cookie!", time()+60*60*24, "/tutorials/php/", "www.html.net");   
  
 // Write the information to the client
 echo $_COOKIE ["HTMLTest"];    

 ?>

 

Arrays In PHP



An array is a set of indexed elements where each has its own, unique identification number.
Sound confusing? It's actually not that complicated.
Imagine a list of words separated by commas. It is called a comma-separated list, and it could, for example, look like this:

apples, pears, bananas, oranges, lemons

 
Then try to imagine dividing the list at each comma. Next, give each section a unique identification number .

What you see is an array. We can, for example, name the array "fruits". The idea is that we can access the array with a number and get a value back, like this:
fruits(0) = apples
fruits(1) = pears
fruits(2) = bananas
fruits(3) = oranges
fruits(4) = lemons
This is the idea behind arrays. Let us try to use it in practice.

How do you use an array?

We will continue with the fruit example. Step by step, we will make it work as a real array. First, we set a variable equal to the list of fruits:


 <?php

 $fruitlist = "apples, pears, bananas, oranges, lemons";
 
 ?>

 
 
Next, we use the function explode to split the list at each comma:


 <?php
  
 $fruitlist = "apples, pears, bananas, oranges, lemons";
  
 $arrFruits = explode(",", $fruitlist);

 ?>

 
 
Voila! "$arrFruits" is now an array!
Notice that we called the function explode with two arguments:
  1. the list that should be split
  2. and the delimiter - i.e., the character used to split (in this case a comma) - in quotation marks: ",".
Here we use a comma as a delimiter, but you can use any character or word as a delimiter.
Let us try to comment the script and put it into a PHP page:


 <html>
 <head>
 <title>Array</title>
 </head>
 <body>

 <?php
 
 // Comma separated list
 $fruitlist = "apples, pears, bananas, oranges, lemons";
  
 // Create an array by splitting the list (with comma as delimiter)
 $arrFruits = explode(",", $fruitlist);
  
    // Write the values from our array
    echo "<p>The list of fruits:</p>";
  
    echo "<ul>";
    echo "<li>" . $arrFruits[0] . "</li>";
    echo "<li>" . $arrFruits[1] . "</li>";
    echo "<li>" . $arrFruits[2] . "</li>";
    echo "<li>" . $arrFruits[3] . "</li>";
    echo "<li>" . $arrFruits[4] . "</li>";
    echo "</ul>";

 ?>

 </body>
 </html>

Loop through an array

 Now we will look at how you can loop through an array.
When you know how many elements an array contains, it is not a problem defining the loop. You simply start with 0 and let the loop continue to the number of items available. In the example with the fruits, you would loop through the array like this:


 <html>
 <head>
 <title>Array</title>

 </head>
 <body>

 <?php
 
 // Comma separated list
 $fruitlist = "apples, pears, bananas, oranges, lemons";
  
 // Create an array by splitting the list (with a comma as delimiter)
 $arrFruits = explode (",", $fruitlist);
  
    echo "<p>The list of fruits:</p>";
    echo "<ul>";
  
    // Loop through the array $arrFruits
    for ($x=0; $x<=4; $x++) {
       echo "<li>" . $arrFruits[$x] . "</li>";
    }
  
    echo "</ul>";

 ?>
  
 </body>
 </html>

How to find the size of an array

But what if we add another fruit to the list? Then our array will contain one element more - which will get the identification number 5. Do you see the problem? Then we need to change the loop, so it runs from 0 to 5, or else not all of the elements will be included.
Wouldn't it be nice if we automatically could find out how many elements an array contains?
That's exactly what we can do with the function foreach. Now we can make a loop that works regardless of the number of elements:


 <?php
    foreach ($arrFruits as $x) {
       echo $x;
    }
 ?>

 
This loop will work regardless of how many or few elements the array contains.

Another example

Below is another example of how you can use an array to write the name of the month:


 <html>
 <head>
 <title>Array</title>

 </head>
 <body>
 
 <?php
 // Creates array with each month.
 // Creates array with the months. Note the comma before January - because there is no month with the number 0
 $arrMonths = array("","January","February","March","April","May","June","July","August","September","October","November","December");
  
 // Call the array with the number of the month - write to the client
 echo $arrMonths[date("n")];
 ?>

 </body>
 </html>

 

Meta Function



array get_meta_tags ( string $filename [, bool $use_include_path = false ] )

Opens filename and parses it line by line for <meta> tags in the file. The parsing stops at </head>.

Parameters

filename
The path to the HTML file, as a string. This can be a local file or an URL.
Example #1 What get_meta_tags() parses
<meta name="author" content="name">
<meta name="keywords" content="php documentation">
<meta name="DESCRIPTION" content="a php manual">
<meta name="geo.position" content="49.33;-86.59">
</head> <!-- parsing stops here -->
(pay attention to line endings - PHP uses a native function to parse the input, so a Mac file won't work on Unix).
use_include_path
Setting use_include_path to TRUE will result in PHP trying to open the file along the standard include path as per the include_path directive. This is used for local files, not URLs.

 Return Values

Returns an array with all the parsed meta tags.
The value of the name property becomes the key, the value of the content property becomes the value of the returned array, so you can easily use standard array functions to traverse it or access single values. Special characters in the value of the name property are substituted with '_', the rest is converted to lower case. If two meta tags have the same name, only the last one is returned.

Examples

Example #1 What get_meta_tags() returns

<?php// Assuming the above tags are at www.example.com$tags get_meta_tags('http://www.example.com/');// Notice how the keys are all lowercase now, and
// how . was replaced by _ in the key.
echo $tags['author']; // nameecho $tags['keywords']; // php documentationecho $tags['description']; // a php manualecho $tags['geo_position']; // 49.33;-86.59?>




Example #2 What get_meta_tags() returns
<?phpfunction get_meta_data($content)
{
$content = strtolower($content);
$content = preg_replace("'<style[^>]*>.*</style>'siU",'',$content); // strip js
$content = preg_replace("'<script[^>]*>.*</script>'siU",'',$content); // strip css
$split = explode("\n",$content);
foreach (
$split as $k => $v)
{
if (
strpos(' '.$v,'<meta')) {
preg_match_all("/<meta[^>]+(http\-equiv|name)=\"([^\"]*)\"[^>]" . "+content=\"([^\"]*)\"[^>]*>/i",$v, $split_content[],PREG_PATTERN_ORDER);;
}
}
return
$split_content;
}
?>



Example #3 What get_meta_tags() returns


<?php/*
** Extracts and formats meta tag content
*/
function get_meta_data($url, $searchkey='') {
$data = get_meta_tags($url); // get the meta data in an array
foreach($data as $key => $value) {
if(
mb_detect_encoding($value, 'UTF-8, ISO-8859-1', true) != 'ISO-8859-1') { // check whether the content is UTF-8 or ISO-8859-1
$value = utf8_decode($value); // if UTF-8 decode it
}
$value = strtr($value, get_html_translation_table(HTML_ENTITIES)); // mask the content
if($searchkey != '') { // if only one meta tag is in demand e.g. 'description'
if($key == $searchkey) {
$str = $value; // just return the value
}
} else {
// all meta tags
$pattern = '/ |,/i'; // ' ' or ','
$array = preg_split($pattern, $value, -1, PREG_SPLIT_NO_EMPTY); // split it in an array, so we have the count of words
$str .= '<p><span style="display:block;color:#000000;font-weight:bold;">' . $key . ' <span style="font-weight:normal;">(' . count($array) . ' words | ' . strlen($value) . ' chars)</span></span>' . $value . '</p>'; // format data with count of words and chars
}
}
return
$str;
}
$content .= get_meta_data("http://www.example.com/");/*
output looks like this:

description (23 words | 167 chars)
SELFHTML 8.1.2 - Die bekannte Dokumentation zu HTML, JavaScript und CGI/Perl - Tutorial und Referenz, mit etlichen Zusatztips zu Design, Grafik, Projektverwaltung usw.

keywords (13 words | 119 chars)
SELFHTML, HTML, Dynamic HTML, JavaScript, CGI, Perl, Grafik, WWW-Seiten, Web-Seiten, Hilfe, Dokumentation, Beschreibung

etc.

*/
$content .= get_meta_data("http://www.example.com/", "description");
?>

Var "GET" In PHP



$HTTP_GET_VARS contains the same initial information, but is not a superglobal. (Note that 
$HTTP_GET_VARS and $_GET are different variables and that PHP handles them as such)

Example #1 $_GET example

<?phpecho 'Hello ' htmlspecialchars($_GET["name"]) . '!';?>

Assuming the user entered http://example.com/?name=Hannes
The above example will output something similar to:
Hello Hannes! 

Your first step in XML , Introduction




The following points explain the purpose of XML. 

  • XML stands for EXtensible Markup Language
  • XML is a markup language much like HTML.
  • XML was designed to describe data.
  • XML tags are not predefined in XML. You must define your own tags.
  • XML uses a DTD (Document Type Definition) to describe the data.
  • XML with a DTD is designed to be self describing.

The Latest Specifications on XML which are released from W3C Working Group can be viewed here. 

It is important to understand that XML is not a replacement for HTML. The main purpose of HTML is the Format the Data that is presented through Browser. For Displaying data on Handheld Devices WML is used. The purpose of XML is not to Format the Data to be displayed. It's mostly used to store and transfer data and to describe the data. It is device or Language independent and can be used for Transmitting Data to any device. The Parser (Or the Program which is capable of understanding the Tags and returning the Text in a Valid Format) on the corresponding Device will help in displaying the data in required format.

You can define your own tags in XML file. The way these tags will be interpreted will depend on the program which is going to get this XML file. The data embedded within these tags will be used according to logic implemented in the secondary program which is going to get this XML as Feed. This point will be more clear hen we start explaining you about how to use the Parsers in next few pages.

What is JQUERY ?




jQuery is an amazing JavaScript library that makes it easy to create wonderful web effects in just a few lines of code. As the website says:”
“jQuery is a JavaScript library that takes this motto to heart: Writing JavaScript code should be fun. jQuery achieves this goal by taking common, repetitive, tasks, stripping out all the unnecessary markup, and leaving them short, smart and understandable.”
Maybe you are thinking… “Why I would need another JavaScript library”? Just give a try and you will see how simple and powerful it is even if you have already used Moo.fx, Scriptaculous, TW-SACK or Prototype.

Why I should use jQuery?

Simple. In just one glance at the source code of a page using jQuery you’ll see how easy it is to use, how much it accomplishes in so few lines of code, and how graceful it is.
My mind was opened one day when I stumbled across some code written with jQuery. I was flipping through the RSS feeds and reading my daily dose of web design blogs when I came across an example of JavaScript loveliness that used jQuery. Truth be told, the code on that site had some browser related bugs… but the concept was something I hadn’t seen before.

What about the code?

The code looked almost simple. Like nothing I had seen before. It made sense.
I started reading through the documentation and was amazed to see how much could be done with so little extra code.

When you can use jQuery?

You should use jQuery when you need:
  • A small library that gives you powerful control over the Document Object Model
  • With very little effort or work on your part
Or
  • Quick access to AJAX
  • Without a lot of bloat (overhead - wasted code)
  • And some basic animation effects to spice things up
But…
If you need super fancy effects for animation, drag and drop, and super smooth animation then you̢۪ll probably want to use Prototype and one of the many great library created to enhance the effects.

What Is CSS ?




CSS is an acronym for Cascading Style Sheets.

What can I do with CSS?

CSS is a style language that defines layout of HTML documents. For example, CSS covers fonts, colours, margins, lines, height, width, background images, advanced positions and many other things. Just wait and see!

HTML can be (mis-)used to add layout to websites. But CSS offers more options and is more accurate and sophisticated. CSS is supported by all browsers today.

After only a few lessons of this tutorial you will be able to make your own style sheets using CSS to give your website a new great look.

What is the difference between CSS and HTML?

HTML is used to structure content. CSS is used for formatting structured content.

Okay, it sounds a bit technical and confusing. But please continue reading. It will all make sense to you soon.
Back in the good old days when Madonna was a virgin and a guy called Tim Berners Lee invented the World Wide Web, the language HTML was only used to add structure to text. An author could mark his text by stating "this is a headline" or "this is a paragraph" using HTML tags such as <h1> and <p>.

As the Web gained popularity, designers started looking for possibilities to add layout to online documents. To meet this demand, the browser producers (at that time Netscape and Microsoft) invented new HTML tags such as for example <font> which differed from the original HTML tags by defining layout - and not structure.

This also led to a situation where original structure tags such as <table> were increasingly being misused to layout pages instead of adding structure to text. Many new layout tags such as <blink> were only supported by one type of browser. "You need browser X to view this page" became a common disclaimer on web sites.

CSS was invented to remedy this situation by providing web designers with sophisticated layout opportunities supported by all browsers. At the same time, separation of the presentation style of documents from the content of documents, makes site maintenance a lot easier.

What Is JAVASCRIPT ?




The first thing that creates some confusion about JavaScript is its name. In fact, one of the most common questions students raise when approaching JavaScript is:
"Is JavaScript the same as Java?".
Clearing up this basic but important question is our first order of business in this lesson, but by no means the only one. By the end of this lesson you will also know:
  • the difference between JavaScript and Java;
  • what JavaScript can and cannot do.

Are JavaScript and Java the same thing?

No, they are not.
Java (developed by Sun Microsystems) is a powerful and much more complex programming language in the same category as C and C++.
JavaScript was created by Brendan Eich at Netscape and was first introduced in December 1995 under the name of LiveScript. However, it was rather quickly renamed JavaScript, although JavaScript’s official name is ECMAScript, which is developed and maintained by theECMA (European Computer Manufacturer's Association) International organization.
JavaScript is a scripting language, that is, a lightweight programming language that is interpreted by the browser engine when the web page is loaded.
The fact that the JavaScript interpreter is the browser engine itself accounts for some inconsistencies in the way your JavaScript-powered page might behave in different browsers. But don't worry: thankfully, well-established techniques and powerful JavaScript libraries such as jQuery (which will be introduced in later lessons) are here to make things wonderfully easier on us.

Things you can't do with JavaScript

You can't force JavaScript on a browser.

JavaScript runs in the client, that is, the brower. If you use an older browser without support for JavaScript, or if you simply choose to disable JavaScript in your browser, then a JavaScript script can't work.

Conclusion: unlike what happens with languages that run on the server, such as PHP, you never fully know for sure the impact that the browser your website visitors are going to use will have on your script, or whether your visitors will choose to turn JavaScript support off.

You can't access or affect resources from another internet domain with JavaScript.


This is called the Same Origin Policy. Well, how would you like it if all of a sudden all the nice comments your visitors left on your website started to disappear, or to change place in your page because of a naughty JavaScript script running on another website?

This is exactly the kind of nasty situation that the Same Origin Policy is designed to prevent. Conclusion: your JavaScript script can only access resources in your website.

You can't access server resources with JavaScript.



Because JavaScript is a client-side language, it's limited to what can be done in the client, that is, usually in the browser environment. A JavaScript script cannot access server resources such as databases.

Zillion things you can do with JavaScript

With JavaScript you can:

Put text in an HTML page on-the-fly.


Say you want to display a nice thank you message to a user who has just submitted a comment form on your website. Obviously, the message needs to be added after the user has submitted the form.

You could let the server do that. However, if your website is very busy and your server processes hundreds of forms a day, it might take a little while for your thank you message to appear to the user.

Here's JavaScript to the rescue. Because JavaScript runs in the user's browser, the thank you note can be added and displayed on the page almost instantaneously, making your website users happy.

Make your web pages responsive.


Web environments are dynamic, things happen all the time: the web page loads in the browser, the user clicks a button or moves the mouse over a link, etc. These are called events.


With JavaScript you can make the page immediately react to these events the way you choose: for example, by showing or hiding specific page elements, by changing the background color, etc.

Detect visitors' browsers.


You can use a JavaScript script to detect the visitor’s browser, or, even better, you can detect what features a certain browser does or does not support. Depending on the browser and its capabilities, you can choose to load a page specifically tailored to that kind of browser .

Create cookies.


A JavaScript script is great if you want to create cookies so that your visitors can enjoy a personalized experience the next time they visit your website .

Validate web form data.


You can use a JavaScript script to validate form data before the form is submitted to a server. This saves the server from extra processing .

And much ... much more.


Learning JavaScript will enable you to add cool animation effects to your web pages without using an external Flash plug-in, use the newest features of HTML5 such as canvas (to draw directly on your web page) and drag and drop capabilities, integrate your website with external web services such as Facebook, Twitter, etc.

Your first step in JAVASCRIPT , Introduction




JavaScript gives you the freedom to add interactivity and responsiveness to your web pages.
The aim of this tutorial is to provide you with a thorough, yet accessible introduction to JavaScript using snappy explanations and practical tasks to try out right from the start.
No prior knowledge of JavaScript is assumed, but because JavaScript sits within and manipulates web pages, in order to be able to follow along, you should already be familiar with HTML and CSS. If you are new to either or both, you’re advised to step through our HTML and CSS tutorials first.
JavaScript is a lightweight, easy to learn, scripting language. It’s used on almost every website to respond to user actions, validate web forms, detect browser support, and much more.
JavaScript is a web programming language, that is, a language that enables you, the designer of your website, to control how a web page behaves. This makes JavaScript crucially different from HTML, the language that gives structure to your web documents, and CSS, the language that controls the appearance of web pages.
If you know other programming languages such as PHP, most programming concepts and basic JavaScript syntax will sound quite familiar to you. However, if this is not the case, don’t worry: by following along and experimenting with the code, at the end of this hands-on tutorial you’ll be able to spruce up your static web pages with fun effects and fantastic responsiveness for the joy of your website visitors.

Your first step in CSS , Introduction




Cascading Style Sheets (CSS) is a fantastic tool to add layout to your websites. It can save you a lot of time and it enables you to design websites in a completely new way. CSS is a must for anyone working with web design.
This tutorial will get you started with CSS in just a few hours. It is easy to understand and it will teach you all the sophisticated techniques.
Learning CSS is fun. As you go along through the tutorial, remember to take enough time to properly experiment with what you learn in each lesson.
Using CSS requires basic experience with HTML. If you are not familiar with HTML, please start with our HTML tutorial before moving on to CSS.

Which software do I need?

Please avoid using software such as FrontPage, DreamWeaver or Word with this tutorial. Advanced software will not help you learn CSS. Instead, it will limit you and slow down your learning curve significantly.

All you need is a free and simple text editor.

For example, Microsoft Windows comes with a program called Notepad. It is usually located in Accessories in the start menu under Programs. Alternatively, you can use a similar text editor e.g. Pico for Linux or Simple Text for Macintosh.

A simple text editor is ideal for learning HTML and CSS because it doesn't affect or change the codes you type. That way, your successes and errors can only be attributed to yourself - not the software.
You can use any browser with this tutorial. We encourage you to always keep your browser updated and use the latest version.

A browser and a simple text editor is all you need.

Saturday, March 31, 2012

Tables In HTML





Building tables in HTML may at first seem complicated but if you keep cool and watch your step, it is actually strictly logical - just like everything else in HTML.

Example 1:

 <table>
   <tr>
  <td>Cell 1</td>
  <td>Cell 2</td>
   </tr>
   <tr>
  <td>Cell 3</td>
  <td>Cell 4</td>
   </tr>
 </table>

Will look like this in the browser:

Cell  1Cell 2Cell 3Cell 4

What's the difference between <tr> and <td>?

As you will see from the above example, this is probably the most complicated HTML example we have given you so far. Let's break it down and explain the different tags:
3 different elements are used to insert tables:
  • The opening tag <table> and the closing tag </table> starts and ends the table. Logical.
  • <tr> stands for "table row" and starts and ends horizontal rows. Still logical.
  • <td> is short for "table data". This tag starts and ends each cell in the rows of your table. All simple and logical.
Here is what happens in Example 1: the table starts with a <table>, followed by a <tr>, which indicates the beginning of a new row. Two cells are inserted in this row: <td>Cell 1</td> and <td>Cell 2</td>. The row is hereafter closed with a </tr> and a new row <tr> begins immediately after. The new row also contains two cells. The table is closed with </table>.
Just to make it clear: rows are horizontal lines of cells and columns are vertical lines of cells:


Cell 1Cell 2
Cell 3Cell 4


Cell 1 and Cell 2 form a row. Cell 1 and Cell 3 form a column.
In the above example, the table has two rows and two columns. However, a table can have an unlimited number of rows and columns.
Example 2:



 <table>
   <tr>
  <td>Cell 1</td>
  <td>Cell 2</td>
  <td>Cell 3</td>
  <td>Cell 4</td>
   </tr>
   <tr>
  <td>Cell 5</td>
  <td>Cell 6</td>
  <td>Cell 7</td>
  <td>Cell 8</td>
   </tr>
   <tr>
  <td>Cell 9</td>
  <td>Cell 10</td>
  <td>Cell 11</td>
  <td>Cell 12</td>
   </tr>
 </table>

Will look like this in the browser:


Cell 1Cell 2Cell 3Cell 4
Cell 5Cell 6Cell 7Cell 8
Cell 9Cell 10Cell 11Cell 12

Are there any attributes?

Of course there are attributes. For example, the border attribute is used to specify the thickness of the border around your table:
Example 3:


 <table border="1">
   <tr>
  <td>Cell 1</td>
  <td>Cell 2</td>
   </tr>
   <tr>
  <td>Cell 3</td>
  <td>Cell 4</td>
   </tr>
 </table>
 
Will look like this in the browser:

Cell 1Cell 2
Cell 3Cell 4
The thickness of the border is specified in pixels
As with images, you can also set the width of a table in pixels - or alternatively in percentage of the screen:
Example 4:
 
<table border="1" width="30%">
This example will be displayed in the browser as a table with the width of 30% of the screen. Try it yourself.

More attributes?

There are lots of attributes for tables. Here are two more:
  • align: specifies the horizontal alignment of the content in the entire table, in a row or in a single cell. For example, left, center or right.
  • valign: specifies the vertical alignment of the content in a cell. For example, top, middle or bottom.
Example 5:
 
<td align="right" valign="top">Cell 1</td>

What can I insert in my tables?

Theoretically, you can insert anything in tables: text, links and images... BUT tables are meant for presenting tabular data (i.e. data which can be meaningfully presented in columns and rows) so refrain from putting things into tables simply because you want them to be placed next to each other.
In the old days on the Internet - i.e. a few years ago - tables were often used as a layout tool. But if you want to control the presentation of texts and images there is a much cooler way to do it (hint: CSS). But more about that later.

echo function


echo is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function. Additionally, if you want to pass more than one parameter to echo, the parameters must not be enclosed within parentheses.

echo also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. This short syntax only works with the short_open_tag configuration setting enabled.

Example #1 echo examples



<?phpecho "Hello World";

echo 
"This spans
multiple lines. The newlines will be
output as well"
;

echo 
"This spans\nmultiple lines. The newlines will be\noutput as well.";

echo 
"Escaping characters is done \"Like this\".";// You can use variables inside of an echo statement$foo "foobar";$bar "barbaz";

echo 
"foo is $foo"// foo is foobar

// You can also use arrays
$baz = array("value" => "foo");

echo 
"this is {$baz['value']} !"// this is foo !

// Using single quotes will print the variable name, not the value
echo 'foo is $foo'// foo is $foo

// If you are not using any other characters, you can just echo variables
echo $foo// foobarecho $foo,$bar// foobarbarbaz

// Some people prefer passing multiple parameters to echo over concatenation.
echo 'This ''string ''was ''made ''with multiple parameters.'chr(10);
echo 
'This ' 'string ' 'was ' 'made ' 'with concatenation.' "\n";

echo <<<END
This uses the "here document" syntax to output
multiple lines with 
$variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon. no extra whitespace!
END;// Because echo does not behave like a function, the following code is invalid.($some_var) ? echo 'true' : echo 'false';// However, the following examples will work:($some_var) ? print 'true' : print 'false'// print is also a construct, but
// it behaves like a function, so
// it may be used in this context.
echo $some_var 'true''false'// changing the statement around?>