Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,207,528 members, 7,999,347 topics. Date: Monday, 11 November 2024 at 04:22 AM |
Nairaland Forum / Science/Technology / Programming / An Introduction To PHP - Beginners Base (3499 Views)
How To Connect Vb.net Windows Application To Php And My Sql Database / Convert My Cms From Cfm To Php / An Introduction To Programming Using C (2) (3) (4)
An Introduction To PHP - Beginners Base by ify01: 6:59am On Aug 31, 2014 |
This tutorial will cover every thing about PHP. Course outline: > PHP Section One - An Introduction to PHP 1. What is PHP and Why do I need it? 2. What you need to get started 3. Installing and testing Easy PHP 4. Troubleshooting > PHP Two -Getting Started With Variables 1. What is a Variable? 2. Putting text into variables 3. Variables - some practice 4. More variable practice 5. Joining direct text and variable data 6. Adding up in PHP 7. Subtraction 8. Multiplication 9. Division 10. Floating point numbers > PHP Three -Conditional Logic 1. If Statements 2. Using If Statements 3. if ... else 4. if ... else if 5. Comparison Operators 6. NOT Equal To 7. Less Than and Greater Than 8. What these mean: <=, >= 9. The Switch Statement 10. Logical Operators 11. Boolean Values 12. Operator Precedence - a List > PHP Four - Working with HTMLForms 1. The HTML Form 2. The Method Attribute 3. The Post Attribute 4. The Action Attribute 5. The Submit button 6. Getting values from a Text Box 7. Checking if the Submit button was clicked 8. More on the ACTION attribute 9. Keep data the user entered 10. PHP and Radio Buttons 11. PHP and Checkboxes > PHP Five - ProgrammingLoops 1. For Loops 2. A Times Table Programme 3. The Code for the PHP Times Table 4. While Loops 5. Do ... While loops 6. The break statement > PHP Six -Arrays in PHP 1. What is an Array? 2. Setting up an Array in PHP 3. Getting at the values stored in Arrays 4. Arrays - Using Text as Keys 5. Arrays and For Each 6. Sorting Array values 7. Random Keys from an Array 8. The count function 9. Some Array Scripts > PHP Seven -String Manipulation 1. Changing Case 2. Trimming White Space 3. Shuffle characters 4. Finding String Positions with strpos 5. Splitting a line of text 6. Joining text into a single line 7. PHP and Escaping 8. String function list > PHP Eight - Create your ownFunctions 1. An Introduction to Functions 2. Variable scope and functions 3. Functions and Arguments 4. A Function to check for blank text boxes 5. Getting values out of functions 6. By Ref, By Val 7. PHP Server Variables 8. HTTP Header() Function 9. The INCLUDE( ) Function > PHP Nine -Security Issues 1. Security Issues And Form Elements 2. htmlspecialchars( ) 3. strip_tags( ) > PHP Ten - Working WithFiles In PHP 1. An Introduction to Working With Files In PHP 2. Opening a file with readfile( ) 3. Opening a file with fopen( ) 4. Options for fopen( ) 5. Writing to files 6. Working with CSV files 7. Reading a text file into an array 8. File Locations >PHP Eleven -Date and Time Functions in PHP 1. The date( ) function 2. Using the date( ) function 3. The getdate( ) Function > PHP Twelve - PHP andMySQL 1. What you need for these Tutorials 2. Creating a database using phpMyAdmin 3. Setting up Fields in database tables 4. Adding records to a MySQL Table GET FULL COURSE OUTLINE HERE > PHP Section One - An Introduction to PHP 1. What is PHP and Why do I need it? PHP is probably the most popular scripting language on the web. It is used to enhance web pages. With PHP, you can do things like create username and password login pages, check details from a form, create forums, picture galleries, surveys, and a whole lot more. If you've come across a web page that ends in PHP, then the author has written some programming code to liven up the plain, old HTML. PHP is known as a server-sided language. That's because the PHP doesn't get executed on your computer, but on the computer you requested the page from. The results are then handed over to you, and displayed in your browser. Other scripting languages you may have heard of are ASP, Python and Perl. (You don't need to know any of these to make a start on PHP. In fact, these tutorials assume that you have no programming experience at all.) The most popular explanation of just what PHP stands for is "Hypertext Pre-processor". But that would make it HPP, surely? An alternative explanation is that the initials come from the earliest version of the program, which was called Personal Home Page Tools. At least you get the letters "PHP" in the right order! But PHP is so popular that if you're looking for a career in the web design/web scripting industry then you just have to know it! In these tutorials, we'll get you up and running. And, hopefully, it will be a lot easier than you think. Course Files As you follow along with these tutorials, I'll make a link to our Course files. You'll also need to have a server, to test your scripts. Don't worry, though - we've found an easy way to get a server up and running on your own PC. Drop your coments so i can go on. Credits to Brykt Forums on Facebook 3 Likes |
Re: An Introduction To PHP - Beginners Base by brightko: 8:00am On Aug 31, 2014 |
Ride on |
Re: An Introduction To PHP - Beginners Base by hushmail: 8:01am On Aug 31, 2014 |
bro abeg how much to register? |
Re: An Introduction To PHP - Beginners Base by ify01: 8:59am On Aug 31, 2014 |
2. What you need to get started with PHP Before you can write and test your PHP scripts, there's one thing you'll need - a server! Fortunately, you don't need to go out and buy one. In fact, you won't be spending any extra money. That's why PHP is so popular! But because PHP is a server-sided scripting language, you either have to get some web space with a hosting company that supports PHP, or make your computer pretend that it has a server installed. This is because PHP is not run on your PC - it's executed on the server. The results are then sent back to the client PC (your computer). Don't worry if this all sounds a little daunting - we've come across an easier way to get you up and running. We're going to be using some software called Wampserver. This allows you to test your PHP scripts on your own computer. It installs everything you need, if you have a Windows PC. We'll explain how to get it installed in a moment, and where to get it from. But just a word for non-windows users. Apple Users If you have OS X, then try these sites to get up and running with PHP: http://www.onlamp.com/pub/a/mac/2001/12/07/apache.html http://www.entropy.ch/software/macosx/php/ What you're doing here is getting the apache server up and running, so that you can run PHP scripts offline. Pay particular attention to where files are stored, and to the "localhost" address. Linux Users There are quite a few sites out there to help Linux users get up and running with the Apache server and PHP. Here are three sites that are worth checking out: http://en.wikipedia.org/wiki/LAMP_(software_bundle) http://www.php-mysql-tutorial.com/wikis/php-tutorial/installing-php-and-mysql.aspx http://www.phpfreaks.com/tutorials/12/0.php If you know any better ones, I'd be interested in hearing from you! Windows Users OK, back to Wampserver and Windows. First, you need to download the software. You can get it from here (this site has nothing to do with Brykt Forums): Download Wampserver Be sure to click the link for Presentation, as well as the link for Downloads. The Presentation page shows you how to install the file. |
Re: An Introduction To PHP - Beginners Base by bot101(m): 9:07am On Aug 31, 2014 |
please bring it on! |
Re: An Introduction To PHP - Beginners Base by GodMode: 5:28pm On Aug 31, 2014 |
The op has been banned... |
Re: An Introduction To PHP - Beginners Base by dhtml(m): 6:02pm On Aug 31, 2014 |
^^^^I still wonder why you have not yet been banned. Any small thing like this, seun don press the ban button for me. |
Re: An Introduction To PHP - Beginners Base by Raypawer(m): 8:03pm On Aug 31, 2014 |
lwkmd.... GodMode: The op has been banned... |
Re: An Introduction To PHP - Beginners Base by dhtml(m): 9:14pm On Aug 31, 2014 |
Why them ban am and leave the remaining trolls (minus me - no longer a troll). |
Re: An Introduction To PHP - Beginners Base by Nobody: 2:45am On Sep 01, 2014 |
Following |
Re: An Introduction To PHP - Beginners Base by dhtml(m): 8:59am On Sep 01, 2014 |
^^^You sef be troll (see your signature), when seun go ban all these trolls sef? |
Re: An Introduction To PHP - Beginners Base by Nobody: 10:58am On Sep 01, 2014 |
dhtml: ^^^You sef be troll (see your signature), when seun go ban all these trolls sef? I am still learning... He's banning only the Ogas |
Re: An Introduction To PHP - Beginners Base by GodMode: 6:50pm On Sep 01, 2014 |
the real dhtml got banned again... chai that moniker don suffer |
Re: An Introduction To PHP - Beginners Base by Nobody: 12:42pm On Sep 03, 2014 |
codecademy php editor does not work (chrome,firefox,ie,opera),it's annoying,had to check other lessons,( html and css ) and it was loading fast ...error message every time |
Re: An Introduction To PHP - Beginners Base by ify01: 1:31pm On Sep 03, 2014 |
Due to the ban i received why trying to post number 3 and 4 of section One, i have decided to skip them. But if you feel that they are needful, then go to brykt forums and you will get them. |
Re: An Introduction To PHP - Beginners Base by ify01: 1:47pm On Sep 03, 2014 |
> PHP Two -Getting Started With Variables 1. What is a Variable? A variable is just a storage area. You put things into your storage areas (variables) so that you can use and manipulate them in your programmes. Things you'll want to store are numbers and text. If you're ok with the idea of variables, then you can move on. If not, think of them like this. Suppose you want to catalogue your clothing collection. You enlist two people to help you, a man and a woman. These two people are going to be your storage areas. They are going to hold things for you, while you tally up what you own. The man and the woman, then, are variables. You count how many coats you have, and then give these to the man. You count how many shoes you have, and give these to the woman. Unfortunately, you have a bad memory. The question is, which one of your people (variables) holds the coats and which one holds the shoes? To help you remember, you can give your people names! You could call them something like this: mr_coats mrs_shoes But it's entirely up to you what names you give your people (variables). If you like, they could be called this: man_coats woman_shoes Or HimCoats HerShoes But because your memory is bad, it's best to give them names that help you remember what it is they are holding for you. (There are some things your people balk at being called. You can't begin their names with an underscore (_), or a number. But most other characters are fine.) OK, so your people (variables) now have name. But it's no good just giving them a name. They are going to be doing some work for you, so you need to tell them what they will be doing. The man is going to be holding the coats. But we can specify how many coats he will be holding. If you have ten coats to give him, then you do the "telling" like this: mr_coats = 10 So, the variable name comes first, then an equals sign. After the equals sign, you tell your variable what it will be doing. Holding the number 10, in our case. (The equals sign, by the way, is not really an equals sign. It's called an assignment operator. But don't worry about it, at this stage. Just remember that you need the equals sign to store things in your variables.) However, you're learning PHP, so there's something missing. Two things, actually. First, your people (variables) need a dollar sign at the beginning (people are like that). So it would be this: $mr_coats = 10 If you miss the dollar sign out, then your people will refuse to work! But the other thing missing is something really picky and fussy - a semi-colon. Lines of code in PHP need a semi-colon at the end: $mr_coats = 10; If you get any parse errors when you try to run your code, the first thing to check is if you've missed the semi-colon off the end. It's very easy to do, and can be frustrating. The next thing to check is if you've missed out a dollar sign. But back to our people (variables). So the man is holding ten coats. We can do the same thing with the other person (variable): $mrs_shoes = 25; So, $mrs_shoes is holding a value of 25. If we then wanted to add up how many items of clothes we have so far, we could set up a new variable (Note the dollar sign at the begining of the new variable): $total_clothes We can then add up the coats and the shoes. You add up in PHP like this: $total_clothes = $mr_coats $mrs_shoes; Remember, $mr_coats is holding a value of 10, and $mrs_shoes is holding a value of 25. If you use a plus sign, PHP thinks you want to add up. So it will work out the total for you. The answer will then get stored in our new variable, the one we've called $total_clothes. You can also add up like this: $total_clothes = 10 35; Again, PHP will see the plus sign and add the two together for you. Of course, you can add up more than two items: $total_clothes = 10 45 7 38 1640; But the idea is the same - PHP will see plus signs and then add things up. The answer is then stored in your variable name, the one to the left of the equals sign. In the next lesson, we'll take a look at how to put text into variables. |
Re: An Introduction To PHP - Beginners Base by ify01: 7:40pm On Sep 03, 2014 |
2. Putting Text into Variables In our previous lesson, you saw how to put numbers into variables. But you can also put text into your variables. Suppose you want to know something about the coats you own. Are they Winter coats? Jackets? Summer coats? You decide to catalogue this, as well. You can put direct text into your variables. You do it in a similar way to storing numbers: $coats1 = "Winter Coats"; Again, our variable name starts with a dollar sign ($). We've then given it the name coats1. The equals sign follows the variable name. After the equals sign, however, we have direct text - Winter Coats. But notice the double quotation marks around our text. If you don't surround your direct text with quotation marks, then you'll get errors. You can, however, use single quotes instead of double quotes. So you can do this: $coats1 = 'Winter Coats'; But you can't do this: $coats1 = 'Winter Coats"; In the above line, we've started with a single quote and ended with a double quote. This will get you an error. We can store other text in the same way: $coats2 = "Jackets"; $coats3 = "Summer Coats"; The direct text will then get stored in the variable to the left of the equals sign. So, to recap, variables are storage areas. You use these storage areas to manipulate things like text and numbers. You'll be using variables a lot, and on the next few lessons you'll see how they work in practice. Comments please |
Re: An Introduction To PHP - Beginners Base by ify01: 1:57pm On Sep 04, 2014 |
3. Some Practice with PHP Variables In the previous section, you saw what variables are: storage areas to hold things like numbers and text. You tell PHP to remember these values because you want to do something with them. In this section, you'll get some practice using variables. Off we go. Testing variables with PHP First, we'll take a look at how to display what's in your variables. We're going to be viewing our results on a web page. So see if you can get this script working first, because it's the one we'll be building on. Using a text editor like Notepad, or your PHP software, type the following. (You can copy and paste it, if you prefer. But you learn more by typing it out yourself - it doesn't really sink in unless you're making mistakes!) <html> <head> <title>Variables - Some Practice</title> </head> <body> <?php print("It Worked!" ?> </body> </html> When you've finished typing it all, save the page as variables.php. Then Run the script. Remember: when you're saving your work, save it to the WWW folder, as explained before. To run the page, start your browser up and type this in the address bar: http://localhost/variables.php If you've created a folder inside the www folder, then the address to type in your browser would be something like: http://localhost/FolderName/variables.php If you were successful, you should have seen the text "It worked!" displayed in your browser. If so, Congratulations! You have a working server up and running! (If you're using Wampserver, you should see an icon in the bottom right of your screen. Click the icon and select Start All Services from the menu.) The PHP script is only one line long: <?php print("It Worked!" ?> The rest of the script is just plain HTML code. Let's examine the PHP in more detail. We've put the PHP in the BODY section of an HTML page. Scripts can also, and often do, go between the HEAD section of an HTML page. You can also write your script without any HTML. But before a browser can recognise your script, it needs some help. You have to tell it what kind of script it is. Browsers recognise PHP by looking for this punctuation (called syntax): <?php ?> So you need a left angle bracket ( < ) then a question mark ( ? ). After the question mark, type PHP (in upper or lowercase). After your script has finished, type another question mark. Finally, you need a right angle bracket ( > ). You can put as much space as you like between the opening and closing syntax. To display things on the page, we've used print( ). What you want the browser to print goes between the round brackets. If you're printing direct text, then you need the quotation marks (single or double quotes). To print what's inside of a variable, just type the variable name (including the dollar). Finally, the line of code ends as normal - with a semi-colon (. Another way to display things on the page is to use an alternative to print() – echo(). Now let's adapt the basic page so that we can set up some variables. We'll try some text first. Keep the HTML as it is, but change your PHP from this: <?php print("It Worked!" ?> To this: <?php print("It Worked!" ?> OK, it's not much of a change! But spreading your code out over more than one line makes it easier to see what you're doing. Now, it's clear that there's only one line of code - Print. So add this second line to your code (the one in red): <?php $test_String = "It Worked!"; print("It Worked!" ?> We've set up a variable called $test_String. After the equals sign, the text "It Worked!" has been added. The line is then ended with a semi-colon. Don't run your script yet. Change the Print line to this: print($test_String); Then add some comments ... <?php //--------------TESTING VARIABLES------------ $test_String = "It Worked!"; print($test_String); ?> Comments in PHP are for your benefit. They help you remember what the code is supposed to do. A comment can be added by typing two slashes. This tells PHP to ignore the rest of the line. After the two slashes, you can type anything you like. Another way to add a comment, is like this: <?php /* --------------TESTING VARIABLES------------ Use this type of comment if you want to spill over to more than one line. Notice how the comment begin and end. */ $test_String = "It Worked!"; print($test_String); ?> Which ever method you choose, make sure you add comment to your code: they really do help. Especially if you have to send your code to someone else! But you can now run the script above, and test it out. How did you get on? You should have seen that exactly the same text got printed to the page. And you might be thinking - what's the big deal? Well, what you just did was to pass some text to a variable, and then have PHP print the contents of the variable. It's a big step: your coding career has now begun! 1 Like |
Re: An Introduction To PHP - Beginners Base by ify01: 1:58pm On Sep 04, 2014 |
Exercise Change the text "It Worked!" to anything you like. Then run the script again. Try typing some numbers in between your double quotes, instead of text. Exercise Change the double quotes to single quotes. Did it have any effect? Put a single quote at the beginning of your text, and a double quote at the end. What happens when you run the code? Exercise Delete the dollar sign from the variable name. Then run your code. What error did you get? Put the dollar sign back, but now delete the semi-colon. Run your code again? What error did you get, this time? It's well worth remembering these errors - you'll see them a lot when you're starting out! If you see them in future, you'll be better able to correct your errors. Now that you're up and running, we'll do some more variable work in the next section. 1 Like |
Re: An Introduction To PHP - Beginners Base by ify01: 3:50pm On Sep 04, 2014 |
Drop ur comments b4 i countinue |
Re: An Introduction To PHP - Beginners Base by felibrain: 11:38pm On Sep 04, 2014 |
ify01: Drop ur comments b4 i countinueOp what you are doing is VERY WRONG. You don't just lift contents from other people's website without giving them credit. That's bad of you. See the full tutorial on this link www.homeandlearn.co.uk/php/php.html if someone does same to you I'm sure you won't be happy. Bye! |
Re: An Introduction To PHP - Beginners Base by ify01: 10:32am On Sep 05, 2014 |
felibrain:Of course, i won't be happy. But at the beginning i gave a link of where i got it from and that is Brykt Forums. So you should be attacking them not me. How would i know that the guy who posted it there is not the original owner? |
Re: An Introduction To PHP - Beginners Base by felibrain: 7:47pm On Sep 05, 2014 |
ify01:ok bro, no problem. |
Re: An Introduction To PHP - Beginners Base by emmanuelatas(m): 2:50am On Sep 06, 2014 |
I don't know why some people won't just mind their useless business. You know the site why didn't you bring it to us to learn. Please just leave us alone you are not wanted, thanks @felibrain Please ify01 continue please. Leave that idiot 1 Like |
Re: An Introduction To PHP - Beginners Base by emmanuelatas(m): 2:59am On Sep 06, 2014 |
<?php $mumu1 = "Felibrain Na Falling Brain"; print(mumu1); ?> |
Re: An Introduction To PHP - Beginners Base by ify01: 9:24am On Sep 06, 2014 |
emmanuelatas: <?phpBro, your dollar sign in the print statement is missing. It should be like this <?php $cat = "boy"; print($cat); ?> |
Re: An Introduction To PHP - Beginners Base by felibrain: 10:30am On Sep 06, 2014 |
emmanuelatas: <?phpThis is what you get when you teach programing to dull heads who struggled to make a good result in SSCE. YOU ARE TOO DULL PLEASE, After all the explanation on variables you still put up this NONESENSE. |
Abstract, Interface And Adapter Classes / Teach Me How To Become A Programmer / Should It Be Java Or Python For Game Development?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 135 |