note 95187 added to function.wordwrap
| From: | megawilddaddy at gmail dot com | Date: | Thu, 17 Dec 2009 10:51:19 +0000 |
| Subject: | note 95187 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164072@lists.php.net to get a copy of this message | ||
ZendFramework filter for force breaking long words
class My_Filter_BreakLongWords implements Zend_Filter_Interface
{
protected $_maxLength;
public function __construct($maxLength = 10)
{
$this->setMaxLength($maxLength);
}
public function setMaxLength($length)
{
if(!empty($length)) {
$this->_maxLength = $length;
}
}
function filter($text)
{
if (strpos($text, '<') === false) {
$result = $text;
foreach(explode(" ", $text) as $key => $line) {
if (mb_strlen($line, 'UTF-8') > $this->_maxLength) {
$result = str_replace($line, $this->_wordwrap($line, $this->_maxLength,
"­"), $result);
}
}
} else {
$result = preg_replace("/<(.+?)>/", " <$1 > ", $text);
foreach(explode(" ", $result) as $key => $line) {
if (mb_strlen($line, 'UTF-8') > $this->_maxLength) {
$pattern = '/(?!=(<[^<>]+?))('.preg_quote($line,
'/').')(?!([^<>]+?>))/';
$replacement = $this->_wordwrap($line, $this->_maxLength,
"­");
$result = preg_replace($pattern, $replacement, $result);
}
}
}
return $result;
}
// utf-wordwrap
private function _wordwrap($str, $len, $break)
{
return preg_replace("/(.{".$len."})/u", "\${1}".$break, $str);
}
}
----
Server IP: 69.147.83.197
Probable Submitter: 188.162.85.153
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit -- https://master.php.net/note/edit/95187
Del: integrated -- https://master.php.net/note/delete/95187/integrated
Del: useless -- https://master.php.net/note/delete/95187/useless
Del: bad code -- https://master.php.net/note/delete/95187/bad+code
Del: spam -- https://master.php.net/note/delete/95187/spam
Del: non-english -- https://master.php.net/note/delete/95187/non-english
Del: in docs -- https://master.php.net/note/delete/95187/in+docs
Del: other reasons-- https://master.php.net/note/delete/95187
Reject -- https://master.php.net/note/reject/95187
Search -- https://master.php.net/manage/user-notes.php