Bluehost.com Web Hosting $6.95

Whats more efficient? ( echo " "; or <?php echo ?> )

This is a discussion on Whats more efficient? ( echo " "; or <?php echo ?> ) within the PHP General forums, part of the PHP Programming Forums category; Hi everyone, Just a simple doubt and basically your opinion needed. I have an option box on a webpage and ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-22-2003
Ryan A
 
Posts: n/a
Default Whats more efficient? ( echo " "; or <?php echo ?> )

Hi everyone,
Just a simple doubt and basically your opinion needed.

I have an option box on a webpage and have around 10 options on it and have
run into a doubt,
which is more efficient to do:

1.
<option value="1"<?php if($th_order==1){echo " SELECTED"; }
?>>Something1</option>
<option value="2"<?php if($th_order==2){echo " SELECTED"; }
?>>Something2</option>

(or)

2.
instead of having the <?php and ?> mixed in the HTML is it better to
echo/print the whole lines?

Thanks,
-Ryan
Reply With Quote
  #2 (permalink)  
Old 10-22-2003
John W. Holmes
 
Posts: n/a
Default Re: [PHP] Whats more efficient? ( echo " "; or <?php echo ?> )

Ryan A wrote:

> I have an option box on a webpage and have around 10 options on it and have
> run into a doubt,
> which is more efficient to do:
>
> 1.
> <option value="1"<?php if($th_order==1){echo " SELECTED"; }
> ?>>Something1</option>
> <option value="2"<?php if($th_order==2){echo " SELECTED"; }
> ?>>Something2</option>
>
> (or)
>
> 2.
> instead of having the <?php and ?> mixed in the HTML is it better to
> echo/print the whole lines?


Use a template engine to separate your presentation from your logic. :)

--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com
Reply With Quote
  #3 (permalink)  
Old 10-22-2003
Larry E . Ullman
 
Posts: n/a
Default Re: [PHP] Whats more efficient? ( echo " "; or <?php echo ?> )

> which is more efficient to do:
> 1.
> <option value="1"<?php if($th_order==1){echo " SELECTED"; }
> ?>>Something1</option>
> <option value="2"<?php if($th_order==2){echo " SELECTED"; }
> ?>>Something2</option>
> (or)
> 2.
> instead of having the <?php and ?> mixed in the HTML is it better to
> echo/print the whole lines?


Really just a matter of personal preference. If I have a mostly PHP
page, I would use echo to print out chunks of HTML. If I have a mostly
HTML page (or section of a page), I would use separate <?php ?>
sections within it. I doubt you'd notice any performance difference
between the two so use whichever is easier for you to code.

Larry
Reply With Quote
  #4 (permalink)  
Old 10-22-2003
Chris Shiflett
 
Posts: n/a
Default Re: [PHP] Whats more efficient? ( echo " "; or <?php echo ?> )

--- "John W. Holmes" <holmes072000@charter.net> wrote:
> Use a template engine to separate your presentation from your logic. :)


Isn't PHP a templating engine? :-)

Chris

=====
My Blog
http://shiflett.org/
HTTP Developer's Handbook
http://httphandbook.org/
RAMP Training Courses
http://www.nyphp.org/ramp
Reply With Quote
  #5 (permalink)  
Old 10-22-2003
John W. Holmes
 
Posts: n/a
Default Re: [PHP] Whats more efficient? ( echo " "; or <?php echo ?> )

Chris Shiflett wrote:

> --- "John W. Holmes" <holmes072000@charter.net> wrote:
>
>>Use a template engine to separate your presentation from your logic. :)

>
>
> Isn't PHP a templating engine? :-)


Of course it is, but what's that got to do with separating presentation
from logic (business logic)? Each one can be PHP code... :)

Bad answer, I know, because his code could be a PHP "template". I'm sure
it's not, though. I just wanted to give a different answer from the many
"it doesn't matter" answers.

--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com




Reply With Quote
  #6 (permalink)  
Old 10-22-2003
Rolf Brusletto
 
Posts: n/a
Default Re: [PHP] Whats more efficient? ( echo " "; or <?php echo ?> )

I'll just on the template bandwagon, I use smarty. (http://smarty.php.net)

Rolf Brusletto
phpExamples.net

John W. Holmes wrote:

> Ryan A wrote:
>
>> I have an option box on a webpage and have around 10 options on it
>> and have
>> run into a doubt,
>> which is more efficient to do:
>>
>> 1.
>> <option value="1"<?php if($th_order==1){echo " SELECTED"; }
>> ?>>Something1</option>
>> <option value="2"<?php if($th_order==2){echo " SELECTED"; }
>> ?>>Something2</option>
>>
>> (or)
>>
>> 2.
>> instead of having the <?php and ?> mixed in the HTML is it better to
>> echo/print the whole lines?

>
>
> Use a template engine to separate your presentation from your logic. :)
>

Reply With Quote
  #7 (permalink)  
Old 10-22-2003
Jordan S. Jones
 
Posts: n/a
Default Re: [PHP] Whats more efficient? ( echo " "; or <?php echo ?> )

I believe I read someplace once that it is more efficient to have your
php embedded in your HTML where required. Something to do with the
amount of parsing that the engine has to do. However, to reiterate what
Captain John W. Holmes said, using a templating engine does allow you to
better manage the project especially in dealing with maintenance down
the road. I personally prefer to let the business logic create XML and
employ XSLT to do my Html rendering. It may not be the quickest or most
memory efficient, but, in my humble opinion, it is one of the easiest to
maintain.

Jordan S. Jones

Ryan A wrote:

>Hi everyone,
>Just a simple doubt and basically your opinion needed.
>
>I have an option box on a webpage and have around 10 options on it and have
>run into a doubt,
>which is more efficient to do:
>
>1.
><option value="1"<?php if($th_order==1){echo " SELECTED"; }
>?>>Something1</option>
><option value="2"<?php if($th_order==2){echo " SELECTED"; }
>?>>Something2</option>
>
>(or)
>
>2.
>instead of having the <?php and ?> mixed in the HTML is it better to
>echo/print the whole lines?
>
>Thanks,
>-Ryan
>
>
>



--
I am nothing but a poor boy. Please Donate..
https://www.paypal.com/xclick/busine...rency_code=USD
Reply With Quote
  #8 (permalink)  
Old 10-22-2003
Sylvain Giroux
 
Posts: n/a
Default Re: Whats more efficient? ( echo " "; or <?php echo ?> )

echo/print the whole lines will be faster... but you'll probably not
see the difference...

I prefer <?php and ?> mixed in the HTMl because i'm using Dreamweaver
to build website/shopping cart/Intranet/Extranet and with the php/HTML
mixed, you have a good look about what your webpage will be in the
WYSIWYG Dreamweaver Editor window.

Regards.

Sylvain Giroux
Solution Globale Informatique
http://www.solutionglobale.com

ryan@coinpass.com (Ryan A) wrote in message news:<000b01c39842$871723d0$f081aa51@l2zcaxu7emppq h>...
> Hi everyone,
> Just a simple doubt and basically your opinion needed.
>
> I have an option box on a webpage and have around 10 options on it and have
> run into a doubt,
> which is more efficient to do:
>
> 1.
> <option value="1"<?php if($th_order==1){echo " SELECTED"; }
> ?>>Something1</option>
> <option value="2"<?php if($th_order==2){echo " SELECTED"; }
> ?>>Something2</option>
>
> (or)
>
> 2.
> instead of having the <?php and ?> mixed in the HTML is it better to
> echo/print the whole lines?
>
> Thanks,
> -Ryan

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:09 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0