Welcome! Log In Create A New Profile

Advanced

White Space in PHP

Posted by 34699341 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
White Space in PHP
May 11, 2012 11:02PM
I know it's kinda last minute, but I'm adding finishing touches to my portfolio, and was wondering about white space.
If I look at the source of my pages in Firefox they look terrible, to fix them I have to remove white space from my PHP.
Which is better, an HTML document that comes out beautifully, or a PHP document that is a bit easier to read... although I prefer the PHP without tabs...

Don't want to be penalised for style...
avatar
Mac
Re: White Space in PHP
May 13, 2012 04:23PM
PHP then style. In the 3rd year you should be up there with both.
Re: White Space in PHP
June 21, 2012 05:30PM
So I was reading and I found that the de facto stardard for PHP is unofficially set by Zend, because they wrote and maintain the Zend engine which runs PHP.
http://framework.zend.com/manual/en/coding-standard.html

indents should be 4 spaces
braces should be on their own lines
concatination always has a space before and after the operator, although ' , ' is faster than ' . ' for echos
a single ' is preferred to a double "
lines should be no longer than 80 characters, 120 max

Language: PHP
function FooBar() { echo $something; OR echo {$something}; BUT NOT echo ${something}; }


So far as adding PHP in HTML goes, adding a single instruction on one line is okay, crammed right into the HTML, and usually there shouldn't be a need to have more than one line, because all other operations should be contained in a seperate PHP file.
The first column of your PHP should not be indented from the PHP tags.

I think that if you avoid echoing HTML tags, which seems to be the main problem creating uneccesarry white space, you will be okay.
It also seems to me that echoing HTML tags must be bad practice, as you usually want things like presentation, structure and logic to be separate.
If I look back at my project now, I can see that I could have done the whole thing without echoing any tags.

Just some random info.
Sorry, you do not have permission to post/reply in this forum.