<? // this example is about double$ or more
$bye=astalavista;
$d=bye;
print $$d;
/*you will see astalavista on browser
because $$d=${$d}=$bye=astalavista
*/
?>
<br />
<? //this is another example it follows reverse...
$tic=tac;
$$tic=tictac;
print $tac;
//tictac=$$tic=${$tic}=$tac
//You will see tictac on your browser.
?>
Here explained double $ string....
Friday, February 11, 2011
working with variables
I think you have seen a word with dollar sign in php scripts...... They are variables.. I will explain them in this and future posts... So let's create a new file in phppp directory give it a name index2.php or what ever you want and add this codes (please read comments) :
<? $a=11; $b=22; ?>
<? print $a; ?> <br /> <? print $b; ?> <br />
<? print $a."<br />".$b; ?> <br /> //this line is the same with second line . (dot) is a concatenation operator
<? print ($a."<br />".$b); ?> <br /> //you can save your lines with concatenation operator,
<? print "$a+$b="; print $a+$b; ?> //the output of this line 11+22=33 you can use html tags inside of " " ,
//i advise to use short html tags in "", for multiple-lined html codes i advise to close php script line (?>)
//then write html code and then open new php script line (<?)
save it and browse and take a look to source code......
<? $a=11; $b=22; ?>
<? print $a; ?> <br /> <? print $b; ?> <br />
<? print $a."<br />".$b; ?> <br /> //this line is the same with second line . (dot) is a concatenation operator
<? print ($a."<br />".$b); ?> <br /> //you can save your lines with concatenation operator,
<? print "$a+$b="; print $a+$b; ?> //the output of this line 11+22=33 you can use html tags inside of " " ,
//i advise to use short html tags in "", for multiple-lined html codes i advise to close php script line (?>)
//then write html code and then open new php script line (<?)
save it and browse and take a look to source code......
Install Php and configure and create your first page........
1. Install php on Linux
Installing php+apache+mysql is easy on linux. If you are Ubuntu user just go to Synaptyc Package Manager and install php mysql and apache with modules. Your www folder will appear in /var folder.
Installing php on other Linux distributions is easy to, just read the documentation. In some distributions you do not need any installation, like backtrack4 or other....
2. Configure php
Go to your localhost home directory (/var/www on Ubuntu) create phppp (this will be my teaching directory) folder. Go to this directory and create index.php file. Open this file with text editor and type:
Installing php+apache+mysql is easy on linux. If you are Ubuntu user just go to Synaptyc Package Manager and install php mysql and apache with modules. Your www folder will appear in /var folder.
Installing php on other Linux distributions is easy to, just read the documentation. In some distributions you do not need any installation, like backtrack4 or other....
2. Configure php
Go to your localhost home directory (/var/www on Ubuntu) create phppp (this will be my teaching directory) folder. Go to this directory and create index.php file. Open this file with text editor and type:
<?php
echo "hello world... I am a php script"; // i am single line comment.. i will not be displayed on browser...
?> <br />
<script language="php"> // i don't advise this method.....
echo "i think i am php script, too.."; # i am a single line comment, too..
</script> <br />
<? // you must enable short tag in configuration file
echo "hello, i am short tag";
/*
I
am
multi-line
comment, I will not seen on browser, too...
*/
?> <br />
<% echo "I am ASP tag"; // you must enable asp tag %> <br/>
<?
print ("i am in <b>print()</b> tag.... "); // You can use print without brackets, too.....
printf ("i am in <b>printf()</b> tag.... ");
echo "i am in <b>echo</b> tag... ";
?>
Save it and browse it (localhost/phpp) and you will see: echo "hello world... I am a php script"; // i am single line comment.. i will not be displayed on browser...
?> <br />
<script language="php"> // i don't advise this method.....
echo "i think i am php script, too.."; # i am a single line comment, too..
</script> <br />
<? // you must enable short tag in configuration file
echo "hello, i am short tag";
/*
I
am
multi-line
comment, I will not seen on browser, too...
*/
?> <br />
<% echo "I am ASP tag"; // you must enable asp tag %> <br/>
<?
print ("i am in <b>print()</b> tag.... "); // You can use print without brackets, too.....
printf ("i am in <b>printf()</b> tag.... ");
echo "i am in <b>echo</b> tag... ";
?>
hello world... I am a php script
i think i am php script, too..
hello, i am short tag
I am ASP tag
i am in print() tag.... i am in printf() tag.... i am in echo tag...
And browse page source, you will get this code :i think i am php script, too..
hello, i am short tag
I am ASP tag
i am in print() tag.... i am in printf() tag.... i am in echo tag...
hello world... I am a php script<br />
i think i am php script, too..<br />
hello, i am short tag<br />
I am ASP tag<br/>
i am in <b>print()</b> tag.... i am in <b>printf()</b> tag.... i am in <b>echo</b> tag...
You can configure your php from php directory by editing php.ini find short_tag and asp_tag lines and edit them if you want to enable them...
Subscribe to:
Posts (Atom)