Sunday, March 20, 2011

HOW-TO-INCLUDE-FILE-PHP

Assalamualaikum and selamat sejahtera

Morning!!hope u in good condition or in happy mood...waaa its been a long.....time that i stop posting,huhu..whatever it is...let we start with the new technique that enable us to include a file by using a PHP code.Example,u got a php code and then u want to include some file that content php code too!!wow it sound something new!!ryte2??hahaha..shall we start...off we go!!!

so,we a file that named myFile.txt

inside myFile.txt type:

this is from myFile.txt

close myFile.txt.After that,here is PHP code:

<HTML>
<HEAD>
<TITLE>Include files</TITLE>
</HEAD>

<BODY>
<H3>Normal text here </H3>
This text written in HTML

<H3>Include File here</H3>

<?PHP include "myFile.txt" ; ?>

</ BODY>
</ HTML >

test it!!

okey,then edit myFile.txt.open it and change that text to be like this:


<?PHP

function PrintFromFile( ) {
print "This function from the myFile.php";
}


?>

then save n close it,go to code, search this line:

<?PHP include "myFile.txt" ; ?>  

change it,to be like this:

<?PHP include "myFile.txt" ;
PrintFromFile()
?>

explain:note that,inside the PHP code,we add the name of function that from included file that all.Okey run it!


N/NOTE:anything problem???

Tuesday, March 1, 2011

Header Function PHP

Assalamu'alaikum and selamat sejahtera

Have you ever wonder that a line of code that enable us just go the other website.I meant before this,we just run the php file then it just display as white background and what we can see form address column it just write "http://localhost/...".So,how us to run or execute the php file and then automatically change the address column to any website that we desire.Here is the code:
 
<?PHP
header("Location: http://www.google.com");
?>

run it!so it go to google page ryte?automatically!

N/NOTE:wah!!so fun!!hehe

Special Post:$_SERVER

Assalamu'alaikum and selamat sejahtera

As i know la,we just had 6 post for creating function,well this post it is just for knowledge.ok ?hahaha,well its quite boring if we just had the same title post everyday!So,imagine that you are an admin and then you want to know the information of server and a little bit on visitor like which website the visitor come from,what browser the visitor used.

Here is the code:

<?PHP

foreach($_SERVER as $name => $value) {
print $name . " = " . $value . "<br>";
}

?>

N/NOTE:don't expect me high!on this post....i just know a little bit only...huhuhu,i just know to display that all...but we can learn!!hahaha

Create-new-function-PHP (Part 6)

Assalamu'alaikum and selamat sejahtera

So,now we will learn on the other alternative of the return.Before this,we must type "return" in order the function to return the value to any variable that come from the function.So,we just use one character only!to enable the return value.Here is the example:


<?PHP

$number1 = 120;
calculate_addition($number1);

print $number1;
 
function calculate_addition(&$number1){
$number2 = 10;


if ($number1 > 100) {
$number1=$number1+$number2;
}
 

else {
$number1= $number1-90;
}

}

?>

we just use "&" as the alternative of the return.Compare this code from previous post:

<?PHP
$number1 = 120;
$total = calculate_addition($number1);

print $total;
function calculate_addition($number1){
$number2 = 10;

if ($number1 > 100) {
$number1=$number1+$number2;
}

else {
$number1= $number1-90;
}

return $number1;
}

?>
 


N/NOTE:&!!!!!!

Create-new-function-PHP (Part 5)

Assalamu'alaikum and selamat sejahtera

So,for this post we will learn on how to get value from the function,before we already learn on how display the value of variable from the function.Ok,here is the code:


<?PHP

$number1 = 120;
$total = calculate_addition($number1);
 

print $total;
 
function calculate_addition($number1){
$number2 = 10;


if ($number1 > 100) {
$number1=$number1+$number2;
}
 

else {
$number1= $number1-90;
}
 

return $number1;
}

?>

So for this post,let me explain the new word,"return".the concept is simple is that it is for assigning any variable from outside the function.In our case,we use $total to get the value from the return.So,we just got the value from the function.



 N/NOTE:the function,calculate_addition return the value ,and then $total are the variable that receive the value from the function.Proof:$total = calculate_addition($number1); .Any question?