Learn the Basics of Php (works)

by liammk in Circuits > Websites

2709 Views, 12 Favorites, 0 Comments

Learn the Basics of Php (works)

php-logo-.png
in this instructable ill show you how to:
setup a local web server
code some php

You Will Need

xampp-logo-new.gif
xampp (more about this in next step)
notepad++(optional,but makes coding allot easer)
a web hosting account here (only needed if you want to publish your php code or use more advanced stuff.)

Xampp

noplacelike_mat.jpg
folow this tutorial on how to set up xampp
(if you want me to post one in text just comment bellow)

Echo and Print

code%20small.jpg
all the php you write will be inbetween this



?>

lets start by saying something to do this we use echo.

ok here we go

echo "this is text";
?>

so whats this mean? ill do a brack down

echo
tells the computer to say something

"
tells the computer the string has started

";
tells the computer the string has ended.





Variabels

20-xampp-logo-trio.jpg
what are variabals?
there like cut and past but in php
so whats the point of that

say there was some song string that you used alot like
this is a looooooooooooooooooooooooooooooooong string.
and you dont want to type that every time you want to say it then you would use a variabal. but how? with ease. here:

<?
$long = "this is a looooooooooooooooooooooooooooooooong string.";
print $long
?>
you can also put strings together with a
.
heres how

<?
$str1 = "this is my first string. this is my";
$str2 = "second string.";

echo " $str1.$str2";
?>

put what if i want to say something with $ or "" in it?
use a \.

heres how

<?
echo "Liam said \"the his name is Liam too \"
echo "we will have to charge him \$10";
?>

Php Can Do Math

math_400.jpg
php can do math!
but how?
just follow along!

say i wanted to add 5 and 5 together then i go

<?
str= 5+5;
print "$str";
?>

this will output

10

so now lets to some more advanced math

<?
str=(5.5+4.5)*500+(2*10);
print "$str";
?>
here is a key

add = +
take away = -
divide = /
multiply = *

Resources

Picture6%20Links.jpg