Wednesday, July 28, 2010

Placement of braces and indentation

There exists few styles of placement of braces( {} ) and they are dictated by C-like languages of programming.
1)Rational style
One of the most used styles cuz it was used by creators of C Kernighan and Ritchie.
It is also used by Java programmers a lot.
+ It saves vertical space, which may be very important especially when your code is big.
- Sometimes it is hard to locate { somewhere in the end of a row...
2)Allman's style
Eric Allman is the man who wrote BSD utilities in that style, so this style is sometimes called "BSD style".
+ The area of block operator is easily visually associated with controlling operator.
3)Whitesmith style
+brackets are more easily associated with code.
4) GNU style
It was developed by Free Software Foundation fond.
Within controlling constructions operators should be placed with equal number of spaces.
Note:indetation must be wether 2, 4 or 8 spaces

Tuesday, July 27, 2010

Sorry i did not post so long=)

I am confused wether i should write some lessons in future, if you could then please comment and say wether you want them or not, cuz i may change this blog a bit then...
So i made one class maybe it is unfinished yet....
Class that creates html tables and does manipulations with it....
I would be very thankful if you could maybe advice me on style or correct some mistakes....

Friday, July 23, 2010

Do Web-Scripting Languages Really Need OOP?

The object-oriented revolution has not been without controversy. Although many programmers embraced OOP quickly, others preferred the procedural approach they were used to, and wondered aloud if the extra machinery needed to support OOP wasn’t more trouble than it was worth. Still, there’s no doubt that the revolution has largely succeeded. Most of the popular programming languages in use today are either fully object-oriented or have object-oriented extensions. Also, at least some of the promises about improved productivity and increased code reuse seem to have been realized, as design methodologies like UML and patterns gain greater influence, and as people get more used to subclassing as a standard way to reuse and extend vendorsupplied libraries.
We feel that the benefits of OOP for “major” (that is, compiled) programming languages like Java and C++ are clear. On the other hand, we feel that the benefits of OOP for scripting languages (like Perl and PHP) are less obvious and are most debatable in the case of Web-scripting (PHP).
How is Web scripting different from other kinds of programming tasks? The most obvious difference is simply that Web scripts typically execute quickly and then go away. In other programming situations, you may have RAM-resident objects that live for hours or days and undergo complex evolutions of state that affect their behavior. A typical Web script, on the other hand, might execute for half a second, as it serves up a particular page, and then dies happy. You may knit these scripts together to provide a more extended user experience (using databases, sessions, cookies), but often such efforts are all about making the experience outlive any PHP objects that may or may not be created. More generally, scripting languages like PHP and Perl typically have a less thoroughgoing implementation of OOP than languages like Java, C++, and Smalltalk, and the limitations of implementation make these OOP extensions less attractive.
This is not to say that there aren’t still benefits of OOP in PHP. In addition to the conceptual benefits that may result from structuring code in an object-centered way, there are two good reasons to use PHP objects:
1) It’s a good way to distribute third-party code for reuse;
2) Many programmers who are used to OO syntax from other languages won’t feel comfortable unless they can use the same idioms in PHP.
But our main point is that use of PHP constructs for OOP is a very “tradeoffy” and pragmatic decision, which we have often seen made more on the basis of religion or fashion. If you are comfy with OO, this kind of syntax is there for you; and if you work in a group that has decided to write in that style, you may want to let the majority rule. If you decide not to go OO, however, be strong—we urge you not to be swayed by the moral-superiority arguments you may hear from people who disdain your five-line procedural script in favor of their ten-line OO script that does exactly the same task.
Taken from PHP and MYSQL Bible

Thursday, July 22, 2010

Lets put our knowledge to use!

< ?php
$massive1=array(array("1a","2a","3a","4a","5a","6a"), array("1b","2b","3b","4b","5b"));
$massive2=array(array("1c","2c","3c","4c","5c"), array("1d","2d","3d","4d","5d"),

$massivelib=array("massive1", "massive2");
foreach( $currentmassive[$v] as $globalmassive[$arv] )
well let's see....
The aim of this code is to make 2 multidimensional arrays become one array.
So what do you need to know to understand this code..... what means ${$variable}.. This is called variables variable.
For example:
$Porche= "red";
here ${$car} has the value of red....
$massiveliblength counts how many of those $massives there we have 2 $massives.
$massivelength counts how many arrays there are in the first $massive.
$currentmassive acts as a pointer and right now it is set on the $massive1.
$arraylength counts how many elements there are in the first array of massive1
foreach( $currentmassive[$v] as $globalmassive[$arv] )
As we see here currentmassive(the massive that is so called pointer $currentmassive on) number $v array is giving its value to the $globalmassive number $arv element.Well its confusing a bit but basically it goes like first $v=0 then $currentmassive[0] is same as $massive1, and you remember how foreach works, so $globalmassive is being created....first is $globalmassive[0]= first element of $massive1 first array. Then after that code within { } is being executed.$arv becomes 1 and now $globalmassive[1]= second element of $massive1 first array and so on...

Tuesday, July 20, 2010

Lesson number two...wohoo programming is as easy as i wished for

So today was a hard day...
PHP is basically variables, arrays, loops: while, for, foreach. and conditions: if elseif else.
Well it's not all that there is to php, but it is kind of basic thing that makes PHP basics.
So here we go....variables.
PHP is a language where you do not need to declare variables(if you never programmed in any other language before just ignore this sentence).Well basically variable is a container for your info...
< ?php
$variable='i am variable';
echo $variable;
so if you see $ before a word it means it is php variable. Here we put in that container string(sentence) "i am variable"...Those single quotes mean that text within them is string. Variable can contain a lot of different stuff...even html code...but if you want it to contain html then you must put it within " " quotes. If you want your information to be ordinary number then you should leave quotes $variable=1;
Massive is what i will speak about now
Massive is a container that contains other smaller containers....
For example
< ?php
So what did we do here? It is actually pretty easy, imagine we have one big big containter named library. Now we put 3 small containers, first one we call "1" and it containes value 1. Second container we call 2 and it contains value 2 and third one we call three and it contains value 3. If you want to output of any small container on your page just echo $array[name of the small container];
if you want to output all three containers and to have space between them then:
echo $bigcontainer[1]." ".$bigcontainer[2]." ".$bigcontainer[three];
dots there mean that " add it next to what you echo"
NOTE: things that are written within [ ] are called key's.
NOW COMES INTERESTING STUFF=) Well that's my personal opinion...
< ?php
some code
echo $car;
echo 'car is empty and it is on standby mode';
echo 'car can contain no more than one get the hell out';
SOOOOOO...i bet you do not understand what the hell is happening if you are newbie=) It is easy actually... some code means that there is some code before that has the value of $car somewhere in it....== is compare $car value with value on the right and if they are equal you get that condition true and the code inside { } is being executed. !== would mean if $car value does not equal value on the right then this condition is true. Well i believe that it is quite simple and you understand it. Just else means that if $car==1 condition is not true and $car==0 is not true then the code that is in else{ } is being executed.
Now comes loop
< ?php
for($i=0; $i<$number_of_people_that_car_can_contain;$i++) {
basically it means that $i has the value of 0 when for first executes code inside { } and it will execute until the condition that $i<$number_blablabla is true. so it means that when $i is 4 it does not execute code inside. and $i++ means that after each loop $i becomes bigger number by 1. FOREACH
< ?php
foreach($array as $key => value)
echo "$key $value"."<>";
NOTE: also possible foreach($array as $value)
So what is the point of it all? You ask me again ..and i answer you again(wow=)) )... foreach works only with arrays and it goes through each element that means if we have an array that contains 5 elements then firstly it will go through 1 element and until the last one. Going through means giving variables $key value of the array key that it is going through right now and giving $value value of current array element value.
means moving onto new line. Output will loock lke this:
one one
2 2
3 3
< ?php
while($i<=2) {
here it does the code until $i value is means that when $i value is 3 it wont execute code within anymore....
THAT'S it now you can do a lot in php...for real all codes consist of those things...well there are some things that are kinda advanced but i dont know about them yet and will try some stuff with those things in next lessons...and look into functions and object oriented programming maybe...

Monday, July 19, 2010

Lesson number one!

Today i set up my first server.
I did it using xampp program. I will not put a link here, since it is availible for everyone and is actually easy to find. XAMPP is really easy program that was adviced in book Wiley - For Dummies PHP and MySQL Web Development All in One. After you downloaded and installed you have to run xampp control panel and run apache server(i runned both apache and mysql).
So....after you have cleared this you need to
"1. Open httpd.conf for editing.
To open the file, choose Start➪Programs➪Apache HTTPD
Server➪Configure Apache Server➪Edit Configuration.
If Edit Configuration isn’t on your Start menu, find the httpd.conf file
on your hard drive, usually in the directory where Apache is installed,
in a conf subdirectory (for example, c:\program files\Apache
group\Apache\conf). Open this file in a text editor, such as Notepad
or WordPad.
2. Activate the PHP module.
Look for the module statement section in the file and locate the following
#LoadModule php6_module “c:/php/php6apache2.dll”
Remove the # from the beginning of the line to activate the module. If
you’re installing PHP 5, you need the following line:
LoadModule php5_module “c:/php/php5apache2.dll”
If you’re using Apache 1.3, rather than Apache 2, the module name is
php6apache.dll or php5apache.dll.
3. Tell Apache which files are PHP programs.
Look for a section describing AddType. This section might contain one
or more AddType lines for other software. The AddType line for PHP is
AddType application/x-httpd-php .php
Look for this line. If you find it with a pound sign at the beginning of the
line, remove the pound sign. If you don’t find the line, add it to the list
of AddType statements. You can specify any extension or series of
This line tells Apache that files with the .php extension are files of the
type application/x-httpd-php. Apache then knows to send files
with .php extensions to the PHP module.
4. Start Apache (if it isn’t running) or restart Apache (if it is running).
You can start it as a service in Windows NT/2000/XP/Vista by choosing
Start➪Programs➪Apache HTTPD Server➪Control Apache Server and
then selecting Start or Restart. You can start it in Windows 98/Me by
choosing Start➪Programs➪Apache Web Server➪Management.
Sometimes restarting Apache isn’t sufficient; you must stop it first and
then start it. In addition, your computer is undoubtedly set up so that
Apache will start whenever the computer starts. Therefore, you can shut
down and then start your computer to restart Apache."
"1. Open the php.ini file for editing.
2. Change the settings you want to change.
Steps 3, 4, and 5 mention some specific settings that you should always
change if you’re using the specified environment.
3. Only if you’re using PHP 5 or earlier, turn off magic quotes.
Look for the following line:
magic_quotes-gpc On
Change On to Off.
4. Only if you’re using PHP 5 or 6 on Windows, activate mysqli or mysql
See instructions in the section “Activating MySQL Support on Windows,”
later in this chapter.
5. Only if you’re using PHP on Windows with the IIS Web server, turn
off force redirect.
Find this line:
;cgi.force_redirect = 1
You need to remove the semicolon so that the setting is active, and also
change the 1 to 0. After the changes, the line looks as follows:
cgi.force_redirect = 0
6. Only if you’re using PHP 5 or later, set your local time zone.
Find the line:
;date.timezone =
Remove the semicolon from the beginning of the line. Add the code for
your local time zone after the equal sign. For instance, the line might be
date.timezone = America/Los_Angeles
You can find a list of time zone codes at
7. Save the php.ini file.
8. Restart your Web server so that the new settings go into effect."
That was taken from the book. Well actually i recommend to download this book or buy it and read whole paragraph about xampp. If you have problems you can write me
Now i recommend you to download notepad++ it is also availible for everyone so search for it yourself. It is quite easy task.
Open your notepad++ and you can start typing your code.
< html>
< head>
< /head>
< body>
< ?php
< /body>
< /html>
This is kind of thing that you type in everytime. < html>< /html> are tags that report to computer that between them is code in html. < head> and < body> are tags where you can insert some objects or text using html. Basically HTML is language that allows you to make tables, insert text and insert pictures in to the website. PHP is language that can be used in html, actually it also works without html, but if you are making web, then both php and html are required...also mysql is useful, but it will come later. starts php code.
following code is between tags.
echo"Hello World!";
this is the very first code that i wrote.
echo means output into the website...
so now save what you have written into the htdocs folder which is located in xampp folder. And save it not as a text but as php...that means for example Helloworld.php...when u save it in notepad++ you can choose it when you are saving...
In order to view the results open browser and write

PS. there is no gap in the beggining < html> < body> < head>

I am learning php

i will post here every single day what i have learned about php, step by step everyday, you should learn it with me. I am using few books and lil' bit of friends help.