I am new to PHP.
I have been using dreamweaver to make html website.
When I am working in PHP, i noticed I had to use echo to put in html command.
for example.
<?php
some php code
//now i want a line break, and I had to do this
echo "<br/>";
?>
is there any easier way to insert html without echo-ing.
It's pretty annoying to have to type all those just to put in a break .
thanks
very basic PHP and HTML question
Moderator: General Moderators
Re: very basic PHP and HTML question
You can do this (if you have lots of html, otherwise I'd just echo it);
Code: Select all
<?php
some php code
//now i want a line break, and I do this
?>
<br/>
<?php
some more php code
?>
Re: very basic PHP and HTML question
what if i have some lines of php, then some lines of html. then some lines of php, then some lines of html. etc etc.
is this bad programming habit to have php and html mixed like that or i just have to put up with that?
is this bad programming habit to have php and html mixed like that or i just have to put up with that?
Re: very basic PHP and HTML question
I suppose it depends who you ask. If you are new to php I wouldn't worry too much about bad habbits, understanding what you are doing and practising is probably more important.
You can close the php tags and type html as many times as you want, the server will only parse the code contained in the <?php ?> tags and it will ignore the rest passing it straight to the clients browser.
It is bad practise in my opinion to mix too much html code into your php, not only does it make code harder to debug but it looks ugly lol. You'll pick up little tricks on how to simplify your code along the way but in the beginning, working code is the main thing.
You can close the php tags and type html as many times as you want, the server will only parse the code contained in the <?php ?> tags and it will ignore the rest passing it straight to the clients browser.
It is bad practise in my opinion to mix too much html code into your php, not only does it make code harder to debug but it looks ugly lol. You'll pick up little tricks on how to simplify your code along the way but in the beginning, working code is the main thing.
-
kalpesh.mahida
- Forum Commoner
- Posts: 36
- Joined: Wed Oct 06, 2010 7:09 am
Re: very basic PHP and HTML question
I think if we consider best practices to write professional html code, should avoid too much line breaks. You can make use of margin and padding instead to make room between html controls.
Re: very basic PHP and HTML question
I use <li> and <ul> for separating things in html.