Page 1 of 1

Adding comments to a multiline echo.

Posted: Sat Nov 27, 2004 7:15 pm
by Shendemiar
I assume it's not possible, but you never know until you're sure...

Would come handy sometimes....

Posted: Sat Nov 27, 2004 7:34 pm
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.

Posted: Sat Nov 27, 2004 8:14 pm
by redmonkey
I assume you mean something like....

Code: Select all

<?php
echo "Hello " . // Hello
     "World";   // World
?>
In which case, yes it is possible.

Posted: Sun Nov 28, 2004 1:54 am
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

Posted: Sun Nov 28, 2004 6:37 am
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
-

Posted: Sun Nov 28, 2004 8:06 pm
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.