Jump to content

Beginning To Learn Php

Recommended Posts

This post will bore to death anyone with just a little PHP knowledge!! I am in the process of learning PHP, using the book "PHP 4 Bible". The book doesn't offer "lessons" or "projects" to learn by, so I thought I'd create my own and share. Like I said...the first several will be VERY BASIC. Please feel free to correct me of any errors, offer further knowledge, or ask questions.


Doing posts like this will help me learn what I'm reading, and maybe it will help someone else out there too!! So, here goes:


Lesson 1: PHP with HTML


PHP and HTML go hand in hand. You can literally take an already designed HTML page and add the PHP

scripts. So how would you do this? You use special tags to "escape from HTML" into PHP and then back

into HTML. You can do this an unlimited number of times within a page. There are four sets of tags

that you can use.



><?PHP    ?>

This is the tag you should use unless you have special reasons for using another set. If you

use this tag, you can be certain that your PHP will be interpreted correctly every time.



><?       ?>

This is the shortest tag of them all, but requires certain steps be accomplished before it can be

used appropriately. Additionally, support was not enabled in the beta versions of PHP 4.



><%       %>

This style also requires accomplishing some steps before it can be used successfully.



><script language="php"></SCRIPT>

This style can be cumbersome in certain situations and is best used with fairly sizable blocks of

PHP code. Be careful if you use lots of Javascript as the close script tags are fatally ambiguous.


Additionally, every PHP statement is terminated by a semi-colon! The script will not work without the

appropriate semi-colons.


Now, it is time for the first lesson. Open a new file in your preferred editor and type the following code.

NOTE: You can use this particular PHP script within normal HTML structure or as stand-alone code. If

you use it within the HTML structure, place the code within the body tags.



	 print (5+5);	//PHP statement(always terminated by semi-colon)

The result will simply be a page generated with the number "10" in the upper left hand corner.

Fairly simple and boring example, but it does illustrate how to use the PHP tags.


Reference for all above material is "PHP 4 Bible" by Tim Converse and Joyce Park; ISBN 0-7645-4716-X

Link to comment
Share on other sites

Thanks for the note. Just to let you know, and anyone else who is interested, I will probably not be able to post the third lesson until sometime next week. I am going on a camping trip this weekend and have much preparation to do. Just didn't want anyone to think that I decided to stop what I'd started. I'm determined to make it all the way through the book, with at least one post per chapter.


Thanks again,


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...