Jump to content

Php document?


tyler

Recommended Posts

After me and y freinds website is big enough were moving to make a php site. The thing is hes expecting me to make it for him and I've seemed to have forgotten the codes. :) So I guess first things first is to lern how to make a PHP site.......I'm going to be reading the tuts and if I don't understanda thing I'll just post a help question here.....Well I'm first gonna learn how to create a PHP document and that I still don't get it.....Hopefully I will

Link to comment
Share on other sites

Hi xlx_drag00n_xlx. Good luck - it'll be a good learning experience.Once you get over the initial shock of learning a new language you'll find that things are quite easy, and all of a sudden everything will fall into place.To give you an example.... ME!! I only started learning html, css, php and sql less than two months ago but already I have been able to create a website, put a database behind it and allow users to query the database. Never would have thought I'd be able to do it. (www.murfituk.com - since you ask.)Don't hesitate to ask questions here if you get really stuck. We're all really friendly.Little tip: don't look just at php on its own as you still need to understand how the php output gets from your server to a user's browser.

Link to comment
Share on other sites

That's right, a good working knowledge of HTML is basically required to use PHP. PHP is powerful, but if you don't have a usable HTML interface to it then it won't do you much good.Also, if you want to develop PHP over the long term, these books will give you a great return on what they cost:http://www.oreilly.com/catalog/progphp2http://www.oreilly.com/catalog/webdbapps2The first one especially is good for people who have knowledge of HTML, but know nothing about PHP. The second should probably not be read until you've read at least the first 4 or 5 chapters of the first book.

Link to comment
Share on other sites

And another thing that I've found is really, really useful is when you include other files into your php document.You can have two files - say start.php and end.php. The start one has basically all your opening html statements - eg doctype, html and headers, meta tags and css doc, plus any standard menu that you want on all your pages.The end one has all the footers and html closing statements.Then all you need to do to create a new page is have:<?phprequire 'start.php';xxxxxrequire 'end.php';?>and the xxxxx bit is really just the main content of that particular page. It saves loads of time because you don't have to keep typing or copying & pasting all the boring stuff that's the same in each page.Its also handy because if you want to change your menu you only have to change the start.php or end.php (depending on where it is) and not each and every single page. But the biggest tip when it comes to php is to get to grips with double quotes and single quotes and escaping characters. Believe me, you can spend hours trying to debug when it all goes wrong and it turns out to be something so simple like you've put a " without escaping it first.My second biggest tip is to understand the three main bracket types () and [] and {}. Its guaranteed to cause problems.

Link to comment
Share on other sites

From what I read from the basix of php tut, it's mostly just variabals?
PHP is a lot more than variables. Variables only hold your data, the rest of PHP is about control flow, logic, functions, data structures, and actually manipulating the data in your variables.This is what the first five chapters of Programming PHP cover:Chapter 1 - Introduction to PHPWhat Does PHP Do?A Brief History of PHPInstalling PHPA Walk Through PHPChapter 2 - Language BasicsLexical StructureData TypesVariablesExpressions and OperatorsFlow-Control StatementsIncluding CodeEmbedding PHP in Web PageChapter 3 - FunctionsCalling a FunctionDefining a FunctionVariable ScopeFunction ParametersReturn ValuesVariable FunctionsAnonymous FunctionsChapter 4 - StringsQuoting String ConstantsPrinting StringsAccessing Individual CharactersCleaning StringsEncoding and EscapingComparing StringsManipulating and Searching StringsRegular ExpressionsPOSIX-Style Regular ExpressionsPerl-Compatible Regular ExpressionsChapter 5 - ArraysIndexed Versus Associative ArraysIdentifying Elements of an ArrayStoring Data in ArraysMultidimensional ArraysExtracting Multiple ValuesConverting Between Arrays and VariablesTraversing ArraysSortingActing on Entire ArraysUsing ArraysThe other chapters cover Objects, Web Techniques, Databases, Graphics, PDF, XML, Security, Application Techniques, Extending PHP, and PHP on Windows, and the book also includes a function reference and extension overview in the appendices. But if you have a good understanding of chapters 1-5 (and also databases), you will know everything you need to know to accomplish most things. The rest of the chapters you can come back and read if you need to work with PDF, or images, or XML or whatever. The chapters on web techniques, application techniques, and security are also good to know, but a little more advanced than the first 5.But I think that a book like this will give you the knowledge you need a lot quicker than trying to do it yourself, regardless what you want to use it for. There's a lot to know with PHP, and it's hard to get it all with online tutorials.
Link to comment
Share on other sites

And another thing that I've found is really, really useful is when you include other files into your php document.You can have two files - say start.php and end.php. The start one has basically all your opening html statements - eg doctype, html and headers, meta tags and css doc, plus any standard menu that you want on all your pages.The end one has all the footers and html closing statements.Then all you need to do to create a new page is have:<?phprequire 'start.php';xxxxxrequire 'end.php';?>and the xxxxx bit is really just the main content of that particular page. It saves loads of time because you don't have to keep typing or copying & pasting all the boring stuff that's the same in each page.Its also handy because if you want to change your menu you only have to change the start.php or end.php (depending on where it is) and not each and every single page. But the biggest tip when it comes to php is to get to grips with double quotes and single quotes and escaping characters. Believe me, you can spend hours trying to debug when it all goes wrong and it turns out to be something so simple like you've put a " without escaping it first.My second biggest tip is to understand the three main bracket types () and [] and {}. Its guaranteed to cause problems.
Man that will save me tonz of time, but what I'm having trouble with the php docs itself. So I just download the php and then what?
Link to comment
Share on other sites

php is server side, you can only process php if you have the php software installed on the web server that hosts your website... some web hosts don't support it.If you have your own server, then go to php.net and download an install it!

Link to comment
Share on other sites

You can use Notepad if you really want, but I would recommend using something like ConTEXT, or there is also a list of good editors in a pinned thread in the General forum. Programmer's editors show code highlighting and give you a lot of features that make programming easier.And yes, PHP documents are just text documents. Here you go:<?phpecho "Hello, world";?>If you don't want to deal with hosting your own server (a home server is good for development though, but I wouldn't host a website from home), you can look into a host like brinkster.com or geekhosting.com, or there is also a thread for hosts in the General forum. You can get hosting for as little as $2/month, which includes everything already installed for you, such as PHP and MySQL.

Link to comment
Share on other sites

  • 2 weeks later...

Hi,I thought I'd jump on this one as I'm a complete beginner at php. I can see that as I'm going to have loads of pages with repetitve stuff I eally need this "include" function to save time when making changes.My questions, which I can't see addressed in the tuts are:1. Do all the files on my site need to be .php files? What about the "index" file. My server says it has php but insists on the index file being .html or .htm.2. Do any of the files need to be .php?3. Does my ".php" file (ie the one I'm going to "include") need to have a "Doctype" and "Head" like .html files?That'll do for now.ThanksMike

Link to comment
Share on other sites

Only files that have php code in them should have an ext. .php (unless you changes the httpd.conf file to accept other file types as a php file)like Cronthenoob said, included files don't need doctype or heading, unless that is the propose of them. PHP is used to make dynamic pages... it writes html and tell it to the browser. so you have one master php file which gets any other kind of file (MySQL, .txt, .php, .html...) and puts it all together into on big html file the browser can use.

Link to comment
Share on other sites

Just to mention, if you have any PHP code in your include file, you will want it to be .php also. You can have it be any extension, but if you have a file called config.ini or something and include it, someone can just browse to the config.ini file on your server and see all of your PHP code. You will want to name every include file .php (unless there is no PHP code in it), and that way the PHP code itself will not be sent to the browser.

Link to comment
Share on other sites

Ok thanks guys but can I clarify a couple of things:1. Is it only the files with php code in that have to be .php files?2. Assuming the answer to 1. is yes, do I have to mention php in the <head>, eg "<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />", in this example 'content= "text/html..."'; should my <head> have some reference here to php?ThanksMike

Link to comment
Share on other sites

Ok thanks guys but can I clarify a couple of things:1. Is it only the files with php code in that have to be .php files?2. Assuming the answer to 1. is yes, do I have to mention php in the <head>, eg "<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />", in this example 'content= "text/html..."'; should my <head> have some reference here to php?ThanksMike
As far as I'm aware1. Yes2. It depends on the page. For example an index page will need it to appear somewhere if your output from the php is html.
Link to comment
Share on other sites

You don't need to do anything to specify PHP. Your browser does not see PHP. PHP code does not get sent to the browser (unless you specifically send it yourself). PHP is used to send HTML to the browser, so the browser still sees HTML. It's just being generated by PHP. You don't need to change the mime type or charset or doctype or anything else, all you use PHP for is backend server logic and processing, and sending HTML output to the browser.You only need to name a file .php if you want it to execute PHP code, but if you are building a site and have some pages with PHP code and some without, it's probably better to just name all of your files .php in case you want to put PHP code in them later. That way your links still work. There is no problem with having only HTML in a .php file. The PHP engine only gets invoked when it finds <?php ?> tags.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...