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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.