Forum Moderators: coopster

Message Too Old, No Replies

general discussion about neat coding

         

jackvull

9:35 pm on Jan 15, 2006 (gmt 0)

10+ Year Member



I find in a lot of my recent php files I have been coding part HTML, part PHP in the files. Stuff like:
<html>
<body>
<form etc.

<?php
some while loops, etc.
?>

more HTML

I recently looked at a copy of some forum software written in PHP and they tend to keep all PHP files as complete PHP. Any HTML that needs to be included is included from a separate include file.
Is this good practice to keep PHP pages neat and easy to understand or is it just up to personal preference?

I find it hard to see how you can have dynamic HTML if you have to include separate include files all the time?

dreamcatcher

10:17 pm on Jan 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Most forums use a templating system which enables you to seperate the code. They also use classes and an OOP approach, which again, can help seperate the data.

It is all down to personal preference really and how you want to lay things out. All because you have messy code, that doesn`t mean the program won`t function how you want it to. However, if you have to leave some coding for a while and come back to it later, its a good idea to comment everything so you know what it is.

dc

phparion

4:50 am on Jan 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



very easy way to learn neat coding style i also learnt it from there

FRONT Page. open it make a smalle page by entering images links etc and then go to HTML view and then see the coding style how it is organized and then while u write coding follow that style and YES write comments with coding it will help u to edit it after sometime.

jackvull

9:39 am on Jan 16, 2006 (gmt 0)

10+ Year Member



It's not so much the indentation of HTML that I am worried but more the mixing up of HTML and PHP code in the same script. You could have hundreds of lines of HTML and then just 20 lines of PHP code mixed up in the script or at the end.

It would be neater just to have an include and then the 20 lines of PHP code but just wondering if there's any tried and tested ways of doing this...

jatar_k

3:32 pm on Jan 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think completely seperating your php and html is foolish, adding overhead for no reason. One of the strengths of PHP (I believe) is how well it works with html.

neat == documented

if it is well documented then you don't need to worrywhat is where.