Append Non-Breaking Space Between Last Two Words

Submitted by:Tom Hanks

Date added:24 January, 2011

Category:PHP

Append Non-Breaking Space Between Last Two Words

Tags: append non-breaking space , php word append , space append

Code Snippet:

<?php

function word_wrapper($text,$minWords = 3) {
$return = $text;
$arr = explode(' ',$text);
if(count($arr) >= $minWords) {
$arr[count($arr) - 2].= '&nbsp;'.$arr[count($arr) - 1];
array_pop($arr);
$return = implode(' ',$arr);
}
return $return;
}

?>
 
 

Comments