Jump to content

How do YOU assemble strings?


wrathican

When coding do you?  

18 members have voted

  1. 1. When coding do you?

    • use echo to print the html on screen
      10
    • open and close the php tags so the html is outside of the php
      6
    • another option? explain...
      2


Recommended Posts

Ive created this poll to see what is the most common/best way to do it...

i personally do it like this:

<ul>
	  <?php 
	  include './include/misc.inc';
	  include './include/opendb.inc';
	  $query = "SELECT * FROM port_section";
	  $result = mysql_query($query);
	  while($row = mysql_fetch_array($result,MYSQL_NUM))
	  {
	  $sect = $row[1];
	  $title = $row[2];
	  ?>
	  <li><a href="?func=views&cat=<?php echo $sect; ?>"><?php echo $title; ?></a></li>
	  <?php
	  }
	  ?>
	  </ul>

whihch is the most effcient way?

Link to comment
Share on other sites

i use heredoc syntax for long bits of HTML that i want to allow designers to edit without having to worry about syntactical issues (like for e-mail messages that use POST variables, etc.).

 

i mainly listen to music while programming, to answer the title question properly.

Link to comment
Share on other sites

I think both would be the most common answer, no one can just never echo html.

 

I'd bet a bunch of people don't know how to shut php on and off for conditional output - I had a partner in college who kept saying that I saw going to get an error about missing a brace =P

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

I use echo, except when there are single and double quotes, then I would consider heredoc.

 

You can escape the double and single quotes easily. All you do is Edit --> Find and Replace --> Find (") Replace (\").

 

Not hard. I don't see the point of using a heredoc, while escaping the quotes is faster and more effiecient.

Link to comment
Share on other sites

I use echo, except when there are single and double quotes, then I would consider heredoc.

 

You can escape the double and single quotes easily. All you do is Edit --> Find and Replace --> Find (") Replace (\").

 

Not hard. I don't see the point of using a heredoc, while escaping the quotes is faster and more effiecient.

 

I don't think it's more efficient? Do you have any sources to verify that? It'll also make your code uglier and harder to read if you have escaped characters in all your strings.

Link to comment
Share on other sites

while escaping the quotes is faster and more effiecient.

 

Unless you're running Google, Yahoo, YouTube, MySpace, etc. then the performance gained by such a "tweak" would be almost negligible.

 

The process for programming web pages which interact with a database should always, IMO, be:

 

1) Write your code such that it is readable and maintainable

 

2) Execute your code in a real world environment, with real data

 

3) Monitor your page load times, if a page loads slowly do the following:

 

3a)  Check all of your queries being executed, update DB indexes as appropriate

 

3b)  Make any changes to actual code next, typically in the form of refactoring or modifying your algorithm / process

 

4) Build your site such that you can turn on performance logging.  When this feature is enabled you're site should notify you of any page or query that takes longer than X seconds to load or execute.  This will help you spend your time optimizing code where it is needed.

Link to comment
Share on other sites

I make it a point to have separate php, html, and js (javascript) files.

Although, I do mostly high function stuff easy on the 'pretty'.  So not a whole lot of HTML to worry about.

Still, if I need to stick a lot of HTML in the middle of php code, I would include it from external file.

.php files are only php code, .js files are only javascript, and so on.

 

Link to comment
Share on other sites

Ive created this poll to see what is the most common/best way to do it...

i personally do it like this:

<ul>
	  <?php 
	  include './include/misc.inc';
	  include './include/opendb.inc';
	  $query = "SELECT * FROM port_section";
	  $result = mysql_query($query);
	  while($row = mysql_fetch_array($result,MYSQL_NUM))
	  {
	  $sect = $row[1];
	  $title = $row[2];
	  ?>
	  <li><a href="?func=views&cat=<?php echo $sect; ?>"><?php echo $title; ?></a></li>
	  <?php
	  }
	  ?>
	  </ul>

whihch is the most effcient way?

echo
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.