Getting into programming is difficult for many people, there are a lot of questions that need answering. Web Development was hard for me, I had struggled with programming in further & higher education. I learned very little in terms of the professional standard that is required from industry level websites. If you are doing a course in university I suggest doing projects solo in your spare time. The best advice I can give is:
Be Fearless, break things, it WILL happen no matter how good you get
The language I will be using is PHP (Hypertext Pre-Processor). HTML(Hypertext Markup Language) is a formatted document of information (<h1>, <h2>, <b>,<a>, <p>). HTML are static the information served to the user is contained within the document, PHP Tags contain code that do process information that comes from either user input/action or a data source(Database/Feed/Text file).
PHP can output different HTML depending on the PHP process e.g instead of writing the HTML of your address book, you can put all the information in a database and use php to repeat the same format for every member of your address book. And PHP will make it look the same but the work required will be significantly less. I will show you how to import data in a later lesson, but for now I want you to grasp the importance of how repeating tasks through programming will make your life simpler.
Both these examples produce the exact same result, the advantage of the php version is that when you get a new contact you can update your database and the php script will respond and show your new contact, with the HTML version you will need to add in the information manually. For a contact list this might not be a huge hassle but what about when your contact list reaches the thousands, what if you want to sort your contact list by. These are all excellent reasons why you should keep information like this in an external data format e.g. if you used a database you would be able to change very quickly how the data is ordered without having to manually move around <li> tags.
Other ways to save time in PHP
Using the date function could be handy when generating a date e.g. If you have a copyright notice on your site and you want to display the current year you can use echo date(‘Y’); which will display the current year. The date function can be adapted to display any date format, if you wanted to show the date as DD/MM/YYYY change the “Y” in the previous example to reflect the characters shown here, you would use echo date(“d/m/Y”); this will display 29/11/2011 on the time of writing & will display todays date.. To display older dates using this function you need to have the date in a specific format known as a unix-timestamp, e.g. echo date(“d/m/Y”, 1317302387) will display 29/11/2011 regardless of the date. Protip: time() will give you the current timestamp.
- trim() removes trailing spaces to the left and right of a bit of information (” Word ” -> “Word”)
- strtolower() makes a peice of information all lower case (“WoRd” -> “word”) – strtoupper() does the opposite
- $_SERVER['REMOTE_ADDR']; returns the users IP address