I am trying to use the following script to fit a paragraph into a box. I cannot understand the following parts of the script. It will be helpful if you explain these lines in brief. An earnest request to my fellow expert PHP developers.
$result .= ($result == '' ? '' : "\n") . $word;
$result .= ($result == '' ? '' : ' ') . $word;
Here is the complete script
//Fits a string into box with given width
function wrapText($string, $fontfile, $fontsize, $angle, $width)
{
$result = '';
$words = explode(' ', $string);
foreach ($words as $word) {
$teststring = $result . ' ' . $word;
$testbox = imagettfbbox($fontsize, $angle, $fontfile, $teststring);
if ($testbox[2] > $width) {
$result .= ($result == '' ? '' : "\n") . $word;
} else {
$result .= ($result == '' ? '' : ' ') . $word;
}
}
return $result;
}