PDA

View Full Version : Ok lets start learning PHP


lionsIT
03-26-2008, 11:48 AM
From today onwards I will post small php tutorials for all you IT lovers :D

if you don't know about php please go to w3schools its the best place to learn.

Today I will show you how to revearse a string without using inbuilt php functions.

try alone before looking at he code.


<?php

$my_string = "make this reverse";
$i = 0;
$output ="";
while($c = $my_string[$i]) // you can accesses each character this way
{
$output = $c.$output; //concatinate $c infront of $output
$i++;
}

echo $output; //esrever siht ekam
?>



:D

TΞΞNSTAR™
03-26-2008, 11:50 AM
aha gud work ... but u got to start frm WHATS PHP .. coz sum dnt knw wats PHP na...

PHP is a powerful server-side scripting language for creating dynamic and interactive websites.
PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft's ASP. PHP is perfectly suited for Web development and can be embedded directly into the HTML code.
The PHP syntax is very similar to Perl and C. PHP is often used together with Apache (web server) on various operating systems. It also supports ISAPI and can be used with Microsoft's IIS on Windows.

Malinga
03-26-2008, 11:52 AM
honda vadak. habai meeka kattiyata therum ganna puluvan aakarayata mula indala ma kalaanum thamai honda. eeta vada PHP virtual host karana vidiyath e magin oya liyana code vala output eka koi aakara venava da kiyana ekath balaganna hati kiyala deela ma karanavanum thamai honda.

shiwankaswe
03-26-2008, 11:53 AM
wow good man

continue that

sriflipflop
03-26-2008, 11:54 AM
good but have to start from basic

kasuncs
03-26-2008, 11:56 AM
Keep going. This is e-learning.

lionsIT
03-26-2008, 12:05 PM
hey guys but there are lot of places where the basics have been done for example w3schools, so is it worth it if I go from the basics? please tell your opinoins

asanka10
03-26-2008, 12:41 PM
hmmm good

lionsIT
03-26-2008, 10:21 PM
Ok Lets start php from the basics.

What is php?
php is a server side scripting language.

Why php?
Free and open source
easy to understand and develope
Great support for mysql(database)
Lot of ready made codes in the Internet

Even the elakiri.com forum is developed using php

Why serverside scripts?
let say that you want to create a login page. you cannot create a login page just using HTML, you need some language(code) to check values entered in the username and password textboxes with the actual values that are stored in the database.
So now you understand that, to do dynamics things in a website you need serverside script language.

OK then enough of theory lets start practicals :lol:

You need a web server to run your php scripts. Apache is a good choice for a webserver(Free).

Download and install wamp server 2, it's a package of apache + php 5 + mysql
this is a simple setup just run it.
http://www.wampserver.com/en/download.php

ok now your set to run your first php program.
open a note pad and enter the code below. save it as hello.php (remeber to select All file in the Save as type: box)

save the file in C:\wamp\www
www - is the root directory of your apache webserver

<php

//This is a comment, these will not be printed, comments are used to describe code

echo "Hello ElaKiri"; //echo will display text in your browser

?>

You will need to stop IIS in your machine if IIS is installed
goto start-> run -> and type NET STOP IISADMIN

Always remeber to start Wamp server before running a php script.
goto start -> programs -> wampserver -> start wamp server
wait until the wamp icon in the icon tray(where your computer time is) turn white.

Open your firefox/ internet explorer and type http://localhost/hello.php (http://localhost/hello.php)
Now you should see a Hello ElaKiri in your browser window.

localhost - it means your computer

thats it you are on your way to become a php Guru :lol:

TΞΞNSTAR™
03-26-2008, 10:35 PM
kwl .. keep it goin bro........

Malinga
03-26-2008, 10:42 PM
oya thiyenne daala hondata. ooka hondai :D wamp valata amatharava Easy Php ekenuth oya kattyuththama karathahaki :D

ravicplk
03-26-2008, 10:53 PM
hey guys but there are lot of places where the basics have been done for example w3schools, so is it worth it if I go from the basics? please tell your opinoins
this is what expert ayya and discuss about......u are the first one to start a thread
thank u for that..please start with basicssssssssss..
we are always with u ..so dont stop ok

ravicplk
03-26-2008, 10:56 PM
what is IIS

sri_lion
03-26-2008, 11:05 PM
what is IIS

IIS is the shorten form for Internet Information Server / Service by Microsoft

lionsIT
03-26-2008, 11:06 PM
IIS - Internet Information Services
Its a web server that comes with windows xp (its a optional install so most probally you may not have IIS)

you can check if its installed by going to
start -> settings -> control panel -> Administartive Tools
if you see Internet Information Services icon that means its installed

ravicplk
03-27-2008, 05:56 AM
IIS is the shorten form for Internet Information Server / Service by Microsoft
thx

ravicplk
03-27-2008, 05:56 AM
IIS - Internet Information Services
Its a web server that comes with windows xp (its a optional install so most probally you may not have IIS)

you can check if its installed by going to
start -> settings -> control panel -> Administartive Tools
if you see Internet Information Services icon that means its installed
thx:D

Sujakshan
03-27-2008, 06:23 AM
thx bro

lionsIT
03-27-2008, 09:14 PM
Hey Guys Lets learn about variables.

just think variable as a box that contain a value. lets see a example

<?php

$my_variable = "elakir"; //you must use $ infront of your varaible name

/* This is another way of commenting, multilines */

/*
Now value elakiri is stored in your $my_variable
Now let see how to print out a variable
*/

echo $my_variable; //This will output elakiri
echo '<br>'; // to get a newline, any html tags can be displayed this way

//What if I do this
echo " $my_variable"; //yes it will print as it is, hope you got the idea

?>
Ok then, lets learn data types in php

<?php
$my_string = "This is a String"; //Strings must be placed between double quotes
$my_int = 10; //if you want to store numbers, remeber not to use qoutes
$my_bool = TRUE; //use this way if you want to store only TRUE/FALSE (1/0)


echo $my_string;
echo '<br>';
echo $my_int;
echo '<br>';
echo $my_bool; // this will print 1 bcos true, if false then 0


?>
Ok then thats it for today
please visit http://www.w3schools.com/php/php_variables.asp
for more nice tutorials

dushan1234
03-27-2008, 09:21 PM
ela wadak macho

ravicplk
03-28-2008, 07:37 AM
good work bro.
continue u r good work,

lionsIT
03-28-2008, 10:55 PM
//What if I do this
echo " $my_variable"; //yes it will print as it is, hope you got the idea



this should be corrected like this,

echo ' $my_variable';

gtkisaru
03-28-2008, 10:58 PM
Good work bro...keep it up..

lionsIT
03-31-2008, 09:24 PM
http://www.w3schools.com/php/php_intro.asp

I have done how to set up php, please visit the above link, it contains all the basics you need to know, just click next and keep reading.

If you find any problems please post them here.

I will however keep writing interesting code sample. :rofl:

ereshthush
03-31-2008, 09:29 PM
ela ela keep it up

gayandinusha
03-31-2008, 09:34 PM
ela ela

lionsIT
04-01-2008, 07:42 PM
Lets see how to get the size of a image (width and height)

<?php
$filename = "1.jpg";
$size = getimagesize($filename); //return an array of details

echo $size[0].'<br>';//width
echo $size[1].'<br>';//height
echo $size[2].'<br>';//image type constant
echo $size[3].'<br>';// both width and height
echo $size['mime'].'<br>';// mime type - image/jpeg

?>

Remeber to give the correct file path, my image file is on the same directory as my php file.

draco
04-01-2008, 07:46 PM
good but have to start from basic


:yes: :yes:

lionsIT
04-01-2008, 09:22 PM
the thing is that there are good tutorials to cover the basics, I have written about it in the post number #24

lionsIT
04-06-2008, 10:25 AM
Today we'll look at some nice php string functions

<?php

$my_string = "this is My String ElaKiri";

$str = strtolower($my_string); // convert all the letters to lower case
echo $str;

$str = strtoupper($my_string); // convert all the letters to Upper case
echo $str;

$str = ucfirst($my_string); // convert First Character to Upper case
echo $str; // This is My String ElaKiri

$str = ucwords($my_string);// convert First Character of all words Upper case
echo $str; // This Is My String ElaKiri

?>

:)

nuwa1
04-06-2008, 10:37 AM
Thanks machan....elakiri. keep it upp ...........