1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

What does this function do?

Discussion in 'PHP' started by baris22, Dec 27, 2008.

  1. #1
    I did not understand this function properly. What does it do?

    Thanks all.

    
    
    function addWrap($curChar,$nextChar,$maxChars,&$finalText,&$tempText,&$curCount,&$tempCount) {
    	$wrapProhibitedChars = "([{!;,\\/:?}])";
    
    	if ($curChar == ' ' || $curChar == "\n")
    	{
    		$finalText .= $tempText . $curChar;
    		$tempText = '';
    		$curCount = 0;
    		$curChar = '';
    	}
    	elseif ($curCount >= $maxChars)
    	{
    		$finalText .= $tempText . ' ';
    		$tempText = '';
    		$curCount = 1;
    	}
    	else
    	{
    		$tempText .= $curChar;
    		$curCount++;
    	}
    
    	// the following code takes care of (unicode) characters prohibiting non-mandatory breaks directly before them.
    
    	// $curChar isn't a " " or "\n"
    	if ($tempText != '' && $curChar != '')
    	{
    		$tempCount++;
    	}
    	// $curChar is " " or "\n", but $nextChar prohibits wrapping.
    	elseif ( ($curCount == 1 && strstr($wrapProhibitedChars,$curChar) !== false) || 
    	         ($curCount == 0 && $nextChar != '' && $nextChar != ' ' && $nextChar != "\n" && strstr($wrapProhibitedChars,$nextChar) !== false))
    	{
    		$tempCount++;
    	}
    	// $curChar and $nextChar aren't both either " " or "\n"
    	elseif (!($curCount == 0 && ($nextChar == ' ' || $nextChar == "\n")))
    	{
    		$tempCount = 0;
    	}
    
    	if ($tempCount >= $maxChars && $tempText == '')
    	{
    		$finalText .= ' ';
    		$tempCount = 1;
    		$curCount = 2;
    	}
    
    	if ($tempText == ''  && $curCount > 0)
    	{
    		$finalText .= $curChar;
    	}
    }
    
    
    PHP:
     
    baris22, Dec 27, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    Wrap texts when words are to long... want to know more?
     
    EricBruggema, Dec 28, 2008 IP
  3. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    How long does text has to be before it wraps it?

    thanks
     
    baris22, Dec 28, 2008 IP