Jump to content

New lines by Default?


random1

Recommended Posts

Are you saying that this

<?php
functiondrawWeb(){$ang=360/$th
is->numpts;$cx=$cy=$this->size
/2;imagesetthickness($this->im
,1);for($i=$this->firstAngle;$
i<=360;$i+=$ang){$a=-deg2rad($
i);$this->angles[]=$a;imagelin
e($this->im,$cx$cy,$cx+$this->
radius1*cos($a),$cy+$this->rad
ius1*sin($a),$this->webcolor);
}$this->angles[]=-deg2rad($thi
s->firstAngle);$rstep=$this->r
adius2/5;for($r=$rstep;$r<=$th
is->radius2;$r+=$rstep){for($i
=0;$i<$this->numpts;$i++){imag
eline($this->im,$cx+$r*cos($th
is->angles[$i]),$cy+$r*sin($th
is->angles[$i]),$cx+$r*cos($th
is->angles[$i+1]),$cy+$r*sin($
this->angles[$i+1]),$this->web
color);}}}

 

is "cleaner" than this

<?php
    function drawWeb() {
        $ang = 360/$this->numpts;
        $cx = $cy = $this->size/2;
        imagesetthickness($this->im, 1);
        for ($i=$this->firstAngle; $i <= 360; $i+=$ang) {
            $a = -deg2rad($i);
            $this->angles[] = $a;
            imageline($this->im, $cx, $cy, $cx+$this->radius1*cos($a), $cy+$this->radius1*sin($a), $this->webcolor);
        }
        $this->angles[] = -deg2rad($this->firstAngle);
        $rstep = $this->radius2/5;
        for ($r=$rstep; $r<=$this->radius2; $r+=$rstep) {
            for ($i=0; $i<$this->numpts; $i++) {
                imageline($this->im,$cx+$r*cos($this->angles[$i]), $cy+$r*sin($this->angles[$i]),
                    $cx+$r*cos($this->angles[$i+1]), $cy+$r*sin($this->angles[$i+1]), $this->webcolor);
            } 
        }
    }

Link to comment
https://forums.phpfreaks.com/topic/97343-new-lines-by-default/#findComment-498138
Share on other sites

What editor are you using to create your PHP scripts? Most PHP editors have a setting for showing a "Right margin" which will display a grey line up to x amount of characters so when you get up to right margin you can decide whether to carry on or go to the next line.

 

If you are outputting very large strings then use the concatenation to split the string into multiple lines, eg:

$str = 'Some very long string here. '. // split long string into multiple lines
       'carry on very long string. '.
       'and so on';

 

The above comes in handy with very long MySQL query's. Query's do not need to be defined in one continuous line.

This will help to eliminate scrolling. Another example :-

 

If you are defining an array which has a lot of items, I prefer to define each array item on a separate line, eg:

$arr = array( 'item1',
              'item2',
              'item3',
              'item4' => array( 'item4_a',
                                'item4_b',
                                'etc' )
            );

 

You do not always have to code very long lines. Try to split them up in some way.

Link to comment
https://forums.phpfreaks.com/topic/97343-new-lines-by-default/#findComment-498748
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.