Monday, 3 September 2018

18 percobaan script html dan php beserta outputnya



Percobaan-1 :

<html>
<body>
<?php echo "Hello World"; ?>
</body>
</html>

Keterangan output Hello World 

Percobaan-2 :
<html>
<body>
<?php
$txt="Hello World";
echo $txt;
?>
</body>
</html>

Keterangan output 
Hello World 

Percobaan-3 :
<html>
<body>
<?php
$txt1="Hello World";
$txt2="1234";
echo $txt1 . " " . $txt2 ;
?>
</body>
</html>

Keterangan output

Hello World 1234


Percobaan-4 :

<html>
<body>
<?php
//This is a comment
/*
This is


a comment block
*/
?>
</body>
</html>

Keterangan output

Blank 

Percobaan-5 : Koding yg salah
<?php
echo "First line <br>"; // You won't see me in the output
// I'm a one liner comment
/*
Same thing, you won't see this in the output file
*/
echo "The above comment spans two lines <br>";
# Hi i'm a Unix shellstyle comment
# Too bad you can't see me
echo "View the source of this file, you'll see no comments here <br>";
?>

Keterangan : kesalahan karena kurang sintak echo ".";


Percobaan-6 :

<?php
$myvar = "Hello"; // valid
$yourVar_is-123 = "World"; // valid
$123ImHere = "Something"; // invalid, starts with number
?>

Keterangan output 
syntax error 

Percobaan 7:

<?php
$a = 1; // $a is a global variable function Test()
{
echo $a; // try to print $a, but $a is not defined here
}
Test();
?>

Keterangan  output
Blank karena a global variable



Percobaan-8 :

<?php
$a = 1; // $a is defined in global scope ...
$b = 2; // $b too function Sum()
{
global $a, $b; // now $a and $b are available in Sum()
$b = $a + $b;
} Sum(); echo $b;
?>
Keterangan : output yang keluar 3 karena penjumlahan a+b = 2+1


Percobaan-9 :
<?php
echo $_SERVER['REMOTE_ADDR'];
?>

Keterangan u\output yang keluar
127.0.0.1 (menunjukan ip dari masingcomputer yang di pakai)


Percobaan-10 :

<?php
echo "My name is {$_GET['name']} <br>";
echo "My friend's name is {$_GET['friend']}";
?>

Keterangan output yang keluar

My name is
My friend's name is


Percobaan-11 :
<?php
$numbers = array(1, 2, 3, 4, 5, 6);
$age = array("mom" => 45, "pop" => 50, "bro" => 25);
$mixed = array("hello" => "World", 2 => "It's two";
echo "numbers[4] = {$numbers[4]} <br>"; echo "My mom's age is {$age['mom']} <br>"; echo "mixed['hello'] = {$mixed['hello']} <br>"; echo "mixed[2] = {$mixed[2'}";
?>

Keterangan output yang di kuarkan error karena penulisan sintak yg salah


Percobaan-12 :

<?php
$myarray = array(1, 2, 3, 4, 5);
$myarray[5] = array("Hi", "Hello", "Konnichiwa", "Apa Kabar");
echo '<pre>'; print_r($myarray); echo '</pre>';
?>

Keterangan output yang keluar
Array
(
[0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5
[5] => Array
(
[0] => Hi
[1] => Hello
[2] => Konnichiwa
[3] => Apa Kabar
)

)

Percobaan-13 :
<?php
$abc = 10; // $abc is an integer
$xyz = (boolean) $abc; // $xyz is a boolean


echo "abc is $abc and xyz is $xyz <br>";
?>

Keterangan output yang keluar abc is 10 and xyz is 1


Percobaan-14 :
<?php
$fruit = 'jamblang';
echo "My favourite fruit is $fruit <br>";
echo 'I lied, actually I hate $fruit <br>';
echo "\r\n My first line \r\n and my second line <br>\r\n";
echo ' Though I use \r\n this string is still on one line <br>';
?>

Keterangan output yang keluar
My favourite fruit is jamblang
I lied, actually I hate $fruit
My first line and my second line
Though I use \r\n this string is still on one line


Percobaan-15 :
<?php
$quote1 = "Never insult Dumbledore " . "in front of me!";
$quote2 = "Nami,
you are my nakama!"; echo $quote1 . "<br>"; echo $quote2;
?>

Keterangan output
Never insult Dumbledore in front of me! Nami, you are my nakama!


Percobaan-16 :

<?php
// print '12'
echo substr('123456789', 0, 2);
// print '56789'
echo substr('123456789', 4);
// print '89'
echo substr('123456789', 2);
// print '456'
echo substr('123456789', 3, 4);


?>

Keterangan output
125678934567894567


Percobaan-17 :

<?php
for ($i = 0; $i < 10; $i++) {
echo '*';
}
?>
Keterangan output
**********

Percobaan-18:

<?php
echo str_repeat('*', 10);
?>
Keterangan output
**********

Download disini

No comments:

Post a Comment