NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP-related book comments

David Sklar sklar at sklar.com
Wed Jul 14 19:17:05 EDT 2004


Chris Shiflett wrote:

> Here's why it annoys me. Run this code:
> 
> <table>
>    <tr>
>       <td>
>          <? echo 'Foo'; ?>
>       </td>
>    </tr>
> </table>
> 
> You'll get this:
> 
> <table>
>    <tr>
>       <td>
>          Foo      </td>
>    </tr>
> </table>
> 
> Yuck. :-)
> 
> The reasoning behind this, as I understand it, is simply to help avoid
> problems caused by undesired output at the end of included files. It seems
> that there is surely a way to avoid the problem without resorting to this
> "solution," but I may be missing something important.

Do you want the output to be:

<table>
     <tr>
        <td>Foo</td>
     </tr>
  </table>

? (I.e. PHP scans backwards from the start tag and forwards from the end 
tag and removes whitespace?)

What if your code is:

<pre>
Top Level
     Next Level
          <?php print $relevant_info; ?>
     End Next Level
End Top Level
</pre>

Then, the whitespace is important.

Perhaps I am missing something.

(BTW, I am also a fan of the leave-the-?>-off-the-end-of-the-file 
technique.)

David




More information about the talk mailing list