note 98123 modified in function.wordwrap by danbrown

From: Date: Tue, 01 Jun 2010 15:02:25 +0000
Subject: note 98123 modified in function.wordwrap by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-169803@lists.php.net to get a copy of this message
If you need a function to cut only words longer than N characters, feel free to use the function below: <?php function wrap($str, $width=75, $break="\n") { return preg_replace('#(\S{'.$width.',})#e', "chunk_split('$1', ".$width.", '".$break."')", $str); } echo wrap('aaaa bbb cc dddd-dddd', 3, ' '); ?> The above example will output: "aaa a bbb cc ddd d-d ddd " --was-- If you need a function to cut only words longer than N characters, feel free to use the function below: <? function wrap($str, $width=75, $break="\n") { return preg_replace('#(\S{'.$width.',})#e', "chunk_split('$1', ".$width.", '".$break."')", $str); } echo wrap('aaaa bbb cc dddd-dddd', 3, ' '); ?> The above example will output: "aaa a bbb cc ddd d-d ddd " http://php.net/manual/en/function.wordwrap.php

« previous php.notes (#169803) next »