Adding comments to a multiline echo.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Adding comments to a multiline echo.

Post by Shendemiar »

I assume it's not possible, but you never know until you're sure...

Would come handy sometimes....
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

all really depends how you are setting it up..

for example

Code: Select all

<?php
//it is possible... notice how this is doing it
?>
look into [php_man]hightlight_string[/php_man].

It would be a lot more helpful if you described what you are really looking on doing.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

I assume you mean something like....

Code: Select all

<?php
echo "Hello " . // Hello
     "World";   // World
?>
In which case, yes it is possible.
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

redmonkey wrote:I assume you mean something like....

Code: Select all

<?php
echo "Hello " . // Hello
     "World";   // World
?>
In which case, yes it is possible.
This'll do great, thanks once again mates :D
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
Hi,

the way suggested is possible, but not very handy I guess.

I prefer this instead: (Has also the advantage, that the comment starts in column 3 and not in 80 or more and is readable/accessable very easy.)

Code: Select all

// comments for foo1
$text .= "foo1"
// comments for foo2
$text .= "foo2"
...
echo $text;
djot
-
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

I think it is all down to personal preference and which ever you find easier to work with. I had to put together a long string today which I wanted to comment and chose to do it like this.....

Code: Select all

<?php

$unpack = 'vversion/'         // version made by                 (2 bytes)
        . 'vextract_version/' // version needed to extract       (2 bytes)
        . 'vgp_bit/'          // general purpose bit             (2 bytes)
        . 'vmethod/'          // compression method              (2 bytes)
        . 'Vmod_time/'        // last modified time and date     (4 bytes)
        . 'Vcrc32/'           // crc32                           (4 bytes)
        . 'Vc_len/'           // compressed length               (4 bytes)
        . 'Vuc_len/'          // uncompressed length             (4 bytes)
        . 'vfn_len/'          // length of filename              (2 bytes)
        . 'vef_len/'          // extra field length              (2 bytes)
        . 'vfcom_len/'        // file comment length             (2 bytes)
        . 'vdisk_start/'      // disk number start               (2 bytes)
        . 'vin_fa/'           // internal file attributes        (2 bytes)
        . 'Vex_fa/'           // external file sttributes        (4 bytes)
        . 'Voffset';          // relative offset of local header (4 bytes)
?>
Had I choosen your preference it would have been...

Code: Select all

<?php

// version made by (2 bytes)        
$unpack  = 'vversion/';    
// version needed to extract (2 bytes)
$unpack .= 'vextract_version/';
// general purpose bit (2 bytes)
$unpack .= 'vgp_bit/'; 
// compression method (2 bytes)
$unpack .= 'vmethod/'; 
// last modified time and date (4 bytes)
$unpack .= 'Vmod_time/';
// crc32 (4 bytes)
$unpack .= 'Vcrc32/'; 
// compressed length (4 bytes)
$unpack .= 'Vc_len/';
// uncompressed length (4 bytes)
$unpack .= 'Vuc_len/';
// length of filename (2 bytes)
$unpack .= 'vfn_len/'; 
// extra field length (2 bytes)
$unpack .= 'vef_len/'; 
// file comment length (2 bytes)
$unpack .= 'vfcom_len/'; 
// disk number start (2 bytes)
$unpack .= 'vdisk_start/';
// internal file attributes (2 bytes)
$unpack .= 'vin_fa/';
// external file sttributes (4 bytes)
$unpack .= 'Vex_fa/'; 
// relative offset of local header (4 bytes)
$unpack .= 'Voffset'; 
?>
For me personally I find it can be quite difficult to pick out the code bits from in between all those comments in the second example.

But, with the first example (for me anyway) the comments are out of the way and don't distract me from the code flow but not to far away that I can't get to them should I need to refer to them.
Post Reply