Jump to content

recommened method of embedding PHP with HTML


cbassett03

Recommended Posts

OK, I've seen this done both ways and want to know which (if any) is the most secure way to do it...

 

I've been coding my pages using echo statements to write HTML, such as:

 

<?php

echo "<p><strong>hello, World!</strong></p>";

echo "<p>You are:$age year(s) old!</p> ";

...

?>

 

and so on...

 

but is this any better

 

<?php

<p><strong>Hello World!</strong></p>

echo "<p><strong>You are $age year(s) old!</p>";

?>

 

 

Is one of these methods better than the other (using ECHO to write actual HTML statements out rather than just embedding them in the script without ECHO)?  Which is the recommended method?

There's no difference in security, it's a matter of style.  I'm assuming you meant this for the second example:

 

<p><strong>Hello World!</strong></p>
<?php
echo "<p><strong>You are $age year(s) old!</p>";
?>

 

I use Smarty templates myself, which are a lot more flexible but they are more effort to set up.  They allow a very clean separation of the display logic and the back end logic.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.