<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test5</title>
</head>
<body>
<?php
// if else
function check($your_number){
if ($your_number < 50){
return "too small";
} else if ( $your_number <100) {
return "medium";
} else{
return "too much babes";
}
}
echo check(20); echo "<br>"; //too small
echo check(60); echo "<br>"; //medium
echo check(120); //too much babes
// switch, break
$grade = 'D';
switch ($grade){
case "A":
echo " you got A grade";
break;
case "B":
echo " not bad";
break;
case "C":
echo "hmm not good";
break;
case "D":
echo " holy sheet what a noob";
break;
} // holy sheet what a noob
//while
$i=1;
while ($i<=100){
echo $i;
echo "<br>";
$i++;
} // 1 - 100
//do while
$iteration=101;
do {echo $iteration;
$iteration++;
// kode bakal dieksekusi minimal sekali walaupun salah
}
while ($iteration <100); // 101
//for
for ($jumlah=1;$jumlah<=5;$jumlah++){
echo $jumlah;
echo "<br>";
} // 1 - 5
//foreach
$array1 = array("satu","dua","tiga","empat");
foreach ($array1 as $variabel){
echo "$variabel <br>";
} // satu dua tiga empat
?>
</body>
</html>
Showing posts with label php. Show all posts
Showing posts with label php. Show all posts
Monday, April 27, 2015
function to manipulate string example in PHP
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>php 3 ex</title>
</head>
<body>
<?php
// strlen() return length of string
// str_word_count() return character count of string
// strrev() return reverse of string
// strpos() search text from a string, return position of char. if not found return false
// str_replace() replace character in string
echo strlen("toro tero"); // 9
echo str_word_count("toro tero mgi"); //3
echo strrev("gokil"); //likog
echo strpos("hello guys im a developer", "develop"); //16
echo str_replace ("here","over","hey you there please come here"); //hey you tover please come over
?>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>php 3 ex</title>
</head>
<body>
<?php
// strlen() return length of string
// str_word_count() return character count of string
// strrev() return reverse of string
// strpos() search text from a string, return position of char. if not found return false
// str_replace() replace character in string
echo strlen("toro tero"); // 9
echo str_word_count("toro tero mgi"); //3
echo strrev("gokil"); //likog
echo strpos("hello guys im a developer", "develop"); //16
echo str_replace ("here","over","hey you there please come here"); //hey you tover please come over
?>
</body>
</html>
php type data examples
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test php2</title>
</head>
<body>
<?php
$x =1000;
$y = "toro";
$z = 123.231;
$anArray = ["toro",1,2,3,4];
$booleans = true;
$kosong = null;
//object
class Human {
function Human(){
$this -> nama = "toro"; // set constructor
}
}
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test php2</title>
</head>
<body>
<?php
$x =1000;
$y = "toro";
$z = 123.231;
$anArray = ["toro",1,2,3,4];
$booleans = true;
$kosong = null;
//object
class Human {
function Human(){
$this -> nama = "toro"; // set constructor
}
}
php syntax & structure test
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>php</title>
</head>
<body>
<?php
echo "helo";
$globVar =100; //global scope
$global2 = 10;
function sum(){
echo 5+2;
}
function tambah($x,$y){
echo "<br>";
echo $x +$y;
//echo "global var". $globVar; -> bakal error. butuh keyword global
return $x +$y;
}
<html lang="en">
<head>
<meta charset="UTF-8">
<title>php</title>
</head>
<body>
<?php
echo "helo";
$globVar =100; //global scope
$global2 = 10;
function sum(){
echo 5+2;
}
function tambah($x,$y){
echo "<br>";
echo $x +$y;
//echo "global var". $globVar; -> bakal error. butuh keyword global
return $x +$y;
}
issues when installing composer
unable to find the socket transport ssl did you forget to enable it when you configured php
i recently found issues when installing composer.
Composer is required to install laravel (php framework).
unable to find the socket transport ssl did you forget to enable it when you configured php/
the issues above spawn when i'm trying to install composer with wampp at localhost. using apache version 2.2.2. To fix the problem we need to change php.ini configuration. usually found at wamp folder installation.
Mine is at C:\wamp\bin\php\php5.3.13\
find php.ini. open with text editor, find this line
;extension=php_openssl.dll
delete that semicolon into
extension=php_openssl.dll
save, retry installation. done. cheers :)
Subscribe to:
Posts (Atom)