jeddi
09-14-2009, 03:22 PM
Hello,
I am trying to figure out how this functiom works so that I can
get it to do what I want.
The function is this:
function wrap_it( $str , $max ){
$str = explode(" ", $str );
$out = "";
$line = "";
foreach($str as $wrd){
$s = (strlen($line." ".$wrd) < $max )?" ":"<br>";
$line = ( $s===" " ) ? $line.$s.$wrd : $wrd;
$out .= $s.$wrd;
}
return $out;
}
I don't understand these two lines:
$s = (strlen($line." ".$wrd) < $max )?" ":"<br>";
$line = ( $s===" " ) ? $line.$s.$wrd : $wrd;
I think they are compacted if statements :o
Can someone show me what they look like in this
format:
if( something) {
do something
}
else {
do something
}
then I might be able to follow whats going on
and fix my problem
Thanks for any help.
I am trying to figure out how this functiom works so that I can
get it to do what I want.
The function is this:
function wrap_it( $str , $max ){
$str = explode(" ", $str );
$out = "";
$line = "";
foreach($str as $wrd){
$s = (strlen($line." ".$wrd) < $max )?" ":"<br>";
$line = ( $s===" " ) ? $line.$s.$wrd : $wrd;
$out .= $s.$wrd;
}
return $out;
}
I don't understand these two lines:
$s = (strlen($line." ".$wrd) < $max )?" ":"<br>";
$line = ( $s===" " ) ? $line.$s.$wrd : $wrd;
I think they are compacted if statements :o
Can someone show me what they look like in this
format:
if( something) {
do something
}
else {
do something
}
then I might be able to follow whats going on
and fix my problem
Thanks for any help.