Page 1 of 1

Error in Loop-HELP

Posted: Wed Jun 07, 2006 9:32 pm
by tecktalkcm0391

Code: Select all

$title = "Soft Drop Shadows";
	$x_size = 0;
	$x_length = strlen($title);
	for($i = 0, $i <= "$x_length"; $i++){
		$x_size = ($x_size + 18);
	}
Why do I get an error, I want it to be what ever the title length is to add 18 to $x_size.

Posted: Wed Jun 07, 2006 9:35 pm
by PrObLeM

Code: Select all

$title = "Soft Drop Shadows";
        $x_size = 0;
        $x_length = strlen($title);
        for($i = 0; $i <= $x_length; $i++){
                $x_size += 18;
        }
that should work. you had $i=0, instead of $i=0;

Posted: Thu Jun 08, 2006 1:08 pm
by phpmash
strlen returns an integer value
so it is not necessary to bound" in $x_length

Posted: Thu Jun 08, 2006 6:20 pm
by nathanr
hmm..

Code: Select all

$title = "Soft Drop Shadows"; 
        $x_size = 0; 
        $x_length = strlen($title); 
        for($i = 0; $i <= $x_length; $i++){ 
                $x_size += 18; 
        }
this would give you an $x_size of 324 ( which is 18*18 ), however title legnth is only 17.. so

Code: Select all

$title = "Soft Drop Shadows"; 
$x_size = strlen($title)*18;
will give you the correct value of 306 ( 17*18 )

:oops: