Little Tips For Php Coder

free web hosting
Free Web Hosting > Computers & Tech > How-To's and Tutorials > Programming > PHP

Little Tips For Php Coder

Silver Bluewater
When you're coding, you happen to get confused with these features although you may not.

"content" <- This is used for including variables with the set of characters

'content ' <- This is used for including every characters as is.

These may be looking too simple tip. I know that.

The matter is this can be really useful for most of the times while you're coding in PHP.

Try it out when you were not aware of these features.

You will like it for sure.


--
Have a nice day!

My blog : silverbluewater.blogspot.com

Reply

BDIT
I am also adding little tips. This is very basic that every php sentence will be ended by a ";". Most beginners make the mistake. They forgot to add a ; sign at the end of the sentence. Another common mistake to the beginner is not to add closing " sign when they use starting " sign. Make me clearer

CODE
echo "This is a tutorial";


This is the valid code, but the common mistakes are not to add closing " sing or ; sign. eg.

CODE
echo "This is a tutorial;

or
CODE
echo "This is a tutorial"


And I also found that few beginners also forget to add "?>" at the end of the php code. They add the starting "<?php" but forget to close it bye adding "?>".

So, the beginners be little careful about the 3 common mistake

1. Omitting closing " sign.
Common mistake
CODE
echo "This is a tutorial;

Correct code
CODE
echo "This is a tutorial";


2. Omitting ; sign
Common mistake
CODE
echo "This is a tutorial"

Correct code
CODE
echo "This is a tutorial";


3. Omitting "?>"
Common mistake
CODE
<?php
echo "This is a tutorial";

Correct code
CODE
<?php
echo "This is a tutorial";
?>


Hope these little tips will help the beginner of php coding.

 

 

 


Reply

Quatrux
in fact, closing the php code, if it's only a PHP file isn't necessary, some programmers even don't close it, to not get headers already sent error, in practice, it's even better to not close the php code with ?> but personally I usually do it, due to I see it to be more clean, but you wonder why it could be a bad idea to close the file?

Sometimes, when closing the php tag ?> you can push enter and leave an empty new line, but php will interpreted it like an output and will output the newline, so sometimes, if you later will decide to use sessions, cookies or headers and etc. you may be getting the Headers already sent error and output was sent there and there, you may have a headache, due to you'll be browsing the file and you won't find any output and usually you won't notice anything in the beginning of the file, the new line or tab, you might think the error message is creating the new line, so this is why in practice if it's only a php file with classes or functions and doesn't output anything, it isn't necessary to close it, it's not even an error, but IT IS an ERROR when for example your doing this:

CODE
<?php echo "Hello World";

<html><head></head><body></body></html>


It's really a bad mistake, because PHP will try to execute the HTML content so you should close the tag. smile.gif

Reply

Mordent
A fantastic piece of advice (in my opinion) for PHP coders - and coding in general - is the joy that is the indent. Tabbing is my generally preferred method, meaning instead of:

CODE
if (foo != bar)
{
while (foo < bar)
{
foo++;
}
}
else
{
if (foo == bar*2)
{
foo = 0;
}
}

Which just looks nasty, and is an absolute nightmare to debug, you get this:

CODE
if (foo != bar)
{
    while (foo < bar)
    {
        foo++;
    }
}
else
{
    if (foo == bar*2)
    {
        foo = 0;
    }
}

Which is far more readable. It's most likely been mentioned in a whole host of other topics, but never underestimate the advantages of good indentation. Some people use spaces instead of tabs, which works pretty well, but I find tabs just look neater (especially as I use Notepad++, which makes grouping this with curly braces a lot clearer). Getting your HTML code to look nice with the use of the echo function is generally a little trickier, although a little more irrelevant, as you'll find that the level of indentation your PHP code is at will most likely not be the same one for HTML code at that point. You can get around this by either ignoring it (as the browser does anyway) or by working out the level of indentation it should be at and tabbing the echo statements in as far as they need to be. This can get a little messy in the PHP itself (as you have two lots of indentation going on at once), but does make the HTML look decidedly more organised.

Either way, the point I'm trying to get across is that 'indentation is generally a good idea'.

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:


Searching Video's for tips, php, coder
advertisement




Little Tips For Php Coder



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE