PHP Beginning Steps

Php

Well here is a small tutorial for advanced php programmers. It is nice to hav all the code ready when you need it.

<?php ................ ?>

<?php print "Here put some text" ; ?>

<img src="<?= "../images/embedded_php.gif" ?>" width="380" height="23" hspace="0" vspace="0">

<script language="php"> print "My First Embedded PHP Example"; </script> - another way to do it

Commenting out

# This is a comment!
// This is also a comment!

/*
This is a set of comments.
This block of multi-line comments can span as many lines as needed.
Be sure you open and close the block with the forward-shash and asterick.
*/

Variables (always use $ sign)

$value = 2000.1212;
$name = "seoandwebdesign.com"; - usual text should be inside quotes

$x = 10; $y = 22; $z = $x + $y;
$result = ((10 + 22) * 4) / ($y + 1);

if ($x > 5) {
print("The value is big enough!<BR>because $x > 5");
}

Constant (always defined only once)

define( "UPPER_LIMIT", 1000 );
define ( "MIN" , 3 );
define ( "SERVERNAME" , "www.myserver.dom" );

Echo (Print) function - (does the same job as print but is faster)

<?php
echo "<B>In most cases, echo will be faster than print!</B><br><br>";

echo "Hello World!<BR><BR>";

echo "This text spans multiple lines.
The newlines will be output, as well.
But, when outputing for HTML rendering you need to add HTML tags!";

echo "<BR><BR><BR>";

echo "This spans<BR>
multiple lines but adds HTML hard breaks!<BR>
Add any HTML code and as much as you want!<BR> It is all just text!<BR><BR>";

// You can use variables inside of an echo statement
$foo = "Hi World!<BR>";
$hello = "Hello World!<BR><BR>";

echo "foo is $foo"; // foo is $foo
echo "hello is $hello"; // hello is $hello

// Single quotes will work differently!
// They print the variable name, not the value!!
echo 'hello is $hello'; // hello is $hello

// you can comma seperate a list of variables!
echo $foo, $hello;

// Some people prefer passing multiple parameters to echo over concatenation.
echo 'This ', 'quick ', 'brown ', 'fox ', 'jumped over the lazy dog.', '<BR>';
echo "(again, ", "and again!)";

?>

 

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.