Basic PHP Script

As a beginning of a series of lessons PHP, first we will learn the basic functions of PHP which will be frequently used in programming with PHP programming language.

One of the most basic function is a function of the PHP echo(). Function echo() is used to display the string that will be translated by the browser, whether in the form of a text string or HTML tag. The syntax of the function echo() is as follows:

echo(“string”)

echo “string”

Example of a simple script using echo() function is as follows:

<html>

<head>

<title>echo() Function</title>

</head>

<body>

<?PHP

echo(“<B>”);

echo “Hello, this is the output of the echo() function”;

echo “</B>”;

?>

</body>

</html>

Store the script named echo.php. If run in a browser results and you see the HTML source code of the script will be written like this:

<html>

<head>

<title>echo() Function</title>

</head>

<body>

<B>Hello, this is the output of the echo() function</B>

</body>

</html>

Use the function echo () is closely related to the use of variable with string data type. String represents a character data type. All characters can be inserted into a string type, including numbers, letters or special characters like +, -,%, $, &, and others. While a variable marked with a $ in front of him. So $var1 is a variable named “var1”.

To enter a string into a variable, must use the following characters: double quotes (“), single quotes (‘), or a smaller sign which is written three times (<<<).

Differences in the use of all three characters are as follows:

If you use double quotes (“), then the variable is located in the string will be expressed as a value, not the name of the variables. Example:

$name = “Petruk”;

echo “My name is $name”;

The results of these examples are “My name is Petruk.”

To declare certain characters in a string, such as quotation marks, the sign ampersand (&), dollar sign ($), and others use the backslash character (\). The character is called the escaped character. Below are given some examples of escaped character:

Escaped character:

1. \n

2. \r

3. \t

4. \$

5. \”

6. \\

7. \&

Means:

1. Line Feed

2. Carriage Return

3. Tab

4. $

5. ”

6. \

7. &

Example usage escaped character:

Echo “He said, \” How are you?\””;

The result is: He said, “How are you?”

If you use single quotes, then all strings will be visible as it is written in single quotes it. The variable will still declared as a variable, and the escaped character, known only \\ and \ ‘. Example:

$name = “Petruk”;

echo ‘My name is $name’;

The result of the example above is not “My name is Petruk”, but “My name is $name.”

The latter is a smaller sign which is written three times (<<<). This sign is called with here doc syntax. Here doc syntax is very useful to write down long strings, because it can be separated into several rows but the result is still in one line. Variables will be declared the contents. The use here doc syntax followed by a kind of marker is written at the beginning and end of the string. Example:

$nama1 = “Petruk”;

$nama2 = “Kucing”;

$nama3 = “Garong”;

echo <<<tanda

Jika namaku adalah $nama1

maka namamu adalah $nama2

dan namanya adalah $nama3

tanda;

Note that the string is located in the here doc syntax does not need to use the mark (;) at the end of the line.

To better understand the use of three kinds of use of the string at the top, would be given examples in the PHP script as follows:

<html>

<head>

<title>PHP Script Example</title>

</head>

<body>

<?PHP

$nama1 = “Petruk”;

$nama2 = “Kucing”;

$nama3 = “Garong”;

echo “Namaku adalah $nama1

“;

echo ‘Namanya adalah $nama2’;

echo ”

Dia berkata, \”Apa kabar?\”

“;

echo <<<tanda

Jika namaku adalah $nama1

maka namamu adalah $nama2

dan namanya adalah $nama3

tanda;

?>

</body>

</html>

Store the script with the name string.php. And run on the browser

Once again as the comparison will be given the HTML source code generated by scripts.

<html>

<head>

<title>PHP Script Example</title>

</head>

<body>

Namaku adalah Petruk

Namanya adalah $nama2

Dia berkata, “Apa kabar?”

Jika namaku adalah Petruk maka namamu adalah Kucing dan namanya adalah Garong

</body>

</html>

As a beginning of a series of lessons PHP, first we will learn the basic functions of PHP which will be frequently used in programming with PHP programming language.

One of the most basic function is a function of the PHP echo(). Function echo() is used to display the string that will be translated by the browser, whether in the form of a text string or HTML tag. The syntax of the function echo() is as follows:

echo(“string”)

echo “string”

Example of a simple script using echo() function is as follows:

<html>

<head>

<title>echo() Function</title>

</head>

<body>

<?PHP

echo(“<B>”);

echo “Hello, this is the output of the echo() function”;

echo “</B>”;

?>

</body>

</html>

Store the script named echo.php. If run in a browser results and you see the HTML source code of the script will be written like this:

<html>

<head>

<title>echo() Function</title>

</head>

<body>

<B>Hello, this is the output of the echo() function</B>

</body>

</html>

Use the function echo () is closely related to the use of variable with string data type. String represents a character data type. All characters can be inserted into a string type, including numbers, letters or special characters like +, -,%, $, &, and others. While a variable marked with a $ in front of him. So $var1 is a variable named “var1”.

To enter a string into a variable, must use the following characters: double quotes (“), single quotes (‘), or a smaller sign which is written three times (<<<).

Differences in the use of all three characters are as follows:

If you use double quotes (“), then the variable is located in the string will be expressed as a value, not the name of the variables. Example:

$name = “Petruk”;

echo “My name is $name”;

The results of these examples are “My name is Petruk.”

To declare certain characters in a string, such as quotation marks, the sign ampersand (&), dollar sign ($), and others use the backslash character (\). The character is called the escaped character. Below are given some examples of escaped character:

Escaped character:

1. \n

2. \r

3. \t

4. \$

5. \”

6. \\

7. \&

Means:

1. Line Feed

2. Carriage Return

3. Tab

4. $

5. ”

6. \

7. &

Example usage escaped character:

Echo “He said, \” How are you?\””;

The result is: He said, “How are you?”

If you use single quotes, then all strings will be visible as it is written in single quotes it. The variable will still declared as a variable, and the escaped character, known only \\ and \ ‘. Example:

$name = “Petruk”;

echo ‘My name is $name’;

The result of the example above is not “My name is Petruk”, but “My name is $name.”

The latter is a smaller sign which is written three times (<<<). This sign is called with here doc syntax. Here doc syntax is very useful to write down long strings, because it can be separated into several rows but the result is still in one line. Variables will be declared the contents. The use here doc syntax followed by a kind of marker is written at the beginning and end of the string. Example:

$nama1 = “Petruk”;

$nama2 = “Kucing”;

$nama3 = “Garong”;

echo <<<tanda

Jika namaku adalah $nama1

maka namamu adalah $nama2

dan namanya adalah $nama3

tanda;

Note that the string is located in the here doc syntax does not need to use the mark (;) at the end of the line.

To better understand the use of three kinds of use of the string at the top, would be given examples in the PHP script as follows:

<html>

<head>

<title>PHP Script Example</title>

</head>

<body>

<?PHP

$nama1 = “Petruk”;

$nama2 = “Kucing”;

$nama3 = “Garong”;

echo “Namaku adalah $nama1

“;

echo ‘Namanya adalah $nama2’;

echo ”

Dia berkata, \”Apa kabar?\”

“;

echo <<<tanda

Jika namaku adalah $nama1

maka namamu adalah $nama2

dan namanya adalah $nama3

tanda;

?>

</body>

</html>

Store the script with the name string.php. And run on the browser

Once again as the comparison will be given the HTML source code generated by scripts.

<html>

<head>

<title>PHP Script Example</title>

</head>

<body>

Namaku adalah Petruk

Namanya adalah $nama2

Dia berkata, “Apa kabar?”

Jika namaku adalah Petruk maka namamu adalah Kucing dan namanya adalah Garong

</body>

</html>

very easy right?🙂

As a beginning of a series of lessons PHP, first we will learn the basic functions of PHP which will be frequently used in programming with PHP programming language.

One of the most basic function is a function of the PHP echo(). Function echo() is used to display the string that will be translated by the browser, whether in the form of a text string or HTML tag. The syntax of the function echo() is as follows:

echo(“string”)

echo “string”

Example of a simple script using echo() function is as follows:

<html>

<head>

<title>echo() Function</title>

</head>

<body>

<?PHP

echo(“<B>”);

echo “Hello, this is the output of the echo() function”;

echo “</B>”;

?>

</body>

</html>

Store the script named echo.php. If run in a browser results and you see the HTML source code of the script will be written like this:

<html>

<head>

<title>echo() Function</title>

</head>

<body>

<B>Hello, this is the output of the echo() function</B>

</body>

</html>

Use the function echo () is closely related to the use of variable with string data type. String represents a character data type. All characters can be inserted into a string type, including numbers, letters or special characters like +, -,%, $, &, and others. While a variable marked with a $ in front of him. So $var1 is a variable named “var1”.

To enter a string into a variable, must use the following characters: double quotes (“), single quotes (‘), or a smaller sign which is written three times (<<<).

Differences in the use of all three characters are as follows:

If you use double quotes (“), then the variable is located in the string will be expressed as a value, not the name of the variables. Example:

$name = “Petruk”;

echo “My name is $name”;

The results of these examples are “My name is Petruk.”

To declare certain characters in a string, such as quotation marks, the sign ampersand (&), dollar sign ($), and others use the backslash character (\). The character is called the escaped character. Below are given some examples of escaped character:

Escaped character:

1. \n

2. \r

3. \t

4. \$

5. \”

6. \\

7. \&

Means:

1. Line Feed

2. Carriage Return

3. Tab

4. $

5. ”

6. \

7. &

Example usage escaped character:

Echo “He said, \” How are you?\””;

The result is: He said, “How are you?”

If you use single quotes, then all strings will be visible as it is written in single quotes it. The variable will still declared as a variable, and the escaped character, known only \\ and \ ‘. Example:

$name = “Petruk”;

echo ‘My name is $name’;

The result of the example above is not “My name is Petruk”, but “My name is $name.”

The latter is a smaller sign which is written three times (<<<). This sign is called with here doc syntax. Here doc syntax is very useful to write down long strings, because it can be separated into several rows but the result is still in one line. Variables will be declared the contents. The use here doc syntax followed by a kind of marker is written at the beginning and end of the string. Example:

$nama1 = “Petruk”;

$nama2 = “Kucing”;

$nama3 = “Garong”;

echo <<<tanda

Jika namaku adalah $nama1

maka namamu adalah $nama2

dan namanya adalah $nama3

tanda;

Note that the string is located in the here doc syntax does not need to use the mark (;) at the end of the line.

To better understand the use of three kinds of use of the string at the top, would be given examples in the PHP script as follows:

<html>

<head>

<title>PHP Script Example</title>

</head>

<body>

<?PHP

$nama1 = “Petruk”;

$nama2 = “Kucing”;

$nama3 = “Garong”;

echo “Namaku adalah $nama1

“;

echo ‘Namanya adalah $nama2’;

echo ”

Dia berkata, \”Apa kabar?\”

“;

echo <<<tanda

Jika namaku adalah $nama1

maka namamu adalah $nama2

dan namanya adalah $nama3

tanda;

?>

</body>

</html>

Store the script with the name string.php. And run on the browser

Once again as the comparison will be given the HTML source code generated by scripts.

<html>

<head>

<title>PHP Script Example</title>

</head>

<body>

Namaku adalah Petruk

Namanya adalah $nama2

Dia berkata, “Apa kabar?”

Jika namaku adalah Petruk maka namamu adalah Kucing dan namanya adalah Garong

</body>

</html>

very easy right?🙂

4 thoughts on “Basic PHP Script

  1. If you need more convincing have a look at What Smoking Can Do
    In your Lungs This is Bryan Curtis. He seemed healthy and fit as he was identified as
    having lung cancer. 12 weeks later on he had been dead.
    This individual was 34 years old.

  2. I completely need to agree which Bull Smoke
    e cigs are new technology cigs which are bound you’re feeling amazed. The particular odorless engineering and high quality flavors require to a new world.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s