note 51861 deleted from function.wordwrap by danbrown

From: Date: Sun, 17 May 2009 18:35:57 +0000
Subject: note 51861 deleted from function.wordwrap by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155142@lists.php.net to get a copy of this message
Note Submitter: hokus_123 at hotmail dot com ---- for ex. msgbrds where HTML hyberlinks occur, wrapping words will devide long URLs and make them invalid. Here is a "real" wordwrap that does not break up HTML hyberlinks. <?PHP function mywordwrap($str, $max = 75, $break = ' ') { // create array by deviding at each occurrence of "<a" $arr = explode('<a', $str); // break up long words in $arr[0] since // it will never contain a hyberlink $arr[0] = preg_replace('/([^\s]{'.$max.'})/i',"$1$break",$arr[0]); // run loop to devide remaining elements for($i = 1; $i < count($arr); $i++) { // devide each element in $arr at each occurrence of "</a>" $arr2 = explode('</a>', $arr[$i]); // break up long words in $arr2 that does not // contain hyberlinks $arr2[1] = preg_replace('/([^\s]{'.$max.'})/i',"$1$break",$arr2[1]); // rejoin $arr2 and assign as element in $arr $arr[$i] = join('</a>', $arr2); } // rejoin $arr to string and return it return join('<a', $arr); } ?>

« previous php.notes (#155142) next »