note 70155 modified in function.wordwrap by thiago
| From: | thiago@php.net | Date: | Mon, 18 Aug 2008 17:26:50 +0000 |
| Subject: | note 70155 modified in function.wordwrap by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-143601@lists.php.net to get a copy of this message | ||
Another function to cut text afterr $limit letters ,
function :
<?php
function wordCut($text, $limit, $msg){
if (strlen($text) > $limit){
$txt1 = wordwrap($text, $limit, '[cut]');
$txt2 = explode('[cut]', $txt1);
$ourTxt = $txt2[0];
$finalTxt = $ourTxt.$msg;
}else{
$finalTxt = $text;
}
return $finalTxt;
}
?>
return :
The limited text
description :
It takes the text, add the string '[cut]' every $limit text by wordwrap, then we explode
the text with '[cut]' and takes the first element in the array which we need !
how to use :
wordCut($my_text, 200, '... read more');
EgypTechno
--was--
Another function to cut text afterr $limit letters ,
function :
function wordCut($text, $limit, $msg){
if (strlen($text) > $limit){
$txt1 = wordwrap($text, $limit, '[cut]');
$txt2 = explode('[cut]', $txt1);
$ourTxt = $txt2[0];
$finalTxt = $ourTxt.$msg;
}else{
$finalTxt = $text;
}
return $finalTxt;
}
return :
The limited text
description :
It takes the text, add the string '[cut]' every $limit text by wordwrap, then we explode
the text with '[cut]' and takes the first element in the array which we need !
how to use :
wordCut($my_text, 200, '... read more');
EgypTechno
http://php.net/manual/en/function.wordwrap.php