note 69947 added to function.strpos
| From: | webmaster at matericosweb dot com | Date: | Wed, 27 Sep 2006 15:39:02 +0000 |
| Subject: | note 69947 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-117736@lists.php.net to get a copy of this message | ||
Jaxolotl,
(bug fixed, sorry)
This Simple function allows you to reduce a long text to an smaller one,
for example when you use articles text previews.
The cool feature is that it doesn't cuts the words,
just search for the first white space after the assigned limit and cuts the phrase there.
<?php
############################################### TEXT REDUCE
function reduce_text($string){
//The Strip_tags() is used to prevent tables or any other tag to be cut unproperly.
$string = strip_tags($string);
//Search the end of a word after [, int offset] and set the result as limit
$limit = @strpos($string, " ",200);
if($limit){ // if string is larger than [, int offset]
//Use $limit to replace width ...Text
return substr_replace($string, "... <em>continue</em>",$limit);
//Change ... <em>continue</em> with anithing you need.
}
else{ //just return text without html tags
return $string;
}
}
?>
----
Server IP: 80.241.173.254
Probable Submitter: 151.41.132.75
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- https://master.php.net/note/edit/69947
Del: integrated -- https://master.php.net/note/delete/69947/integrated
Del: useless -- https://master.php.net/note/delete/69947/useless
Del: bad code -- https://master.php.net/note/delete/69947/bad+code
Del: spam -- https://master.php.net/note/delete/69947/spam
Del: non-english -- https://master.php.net/note/delete/69947/non-english
Del: in docs -- https://master.php.net/note/delete/69947/in+docs
Del: other reasons-- https://master.php.net/note/delete/69947
Reject -- https://master.php.net/note/reject/69947
Search -- https://master.php.net/manage/user-notes.php