very basic PHP and HTML question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shamkawai
Forum Newbie
Posts: 7
Joined: Mon Jan 10, 2011 4:09 pm

very basic PHP and HTML question

Post by shamkawai »

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
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: very basic PHP and HTML question

Post by Neilos »

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

?>
shamkawai
Forum Newbie
Posts: 7
Joined: Mon Jan 10, 2011 4:09 pm

Re: very basic PHP and HTML question

Post by shamkawai »

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?
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: very basic PHP and HTML question

Post by Neilos »

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.
kalpesh.mahida
Forum Commoner
Posts: 36
Joined: Wed Oct 06, 2010 7:09 am

Re: very basic PHP and HTML question

Post by kalpesh.mahida »

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.
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: very basic PHP and HTML question

Post by Neilos »

I use <li> and <ul> for separating things in html.
Post Reply