note 69823 added to function.strpos
| From: | webmaster at matericosweb dot com | Date: | Fri, 22 Sep 2006 08:53:57 +0000 |
| Subject: | note 69823 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-117412@lists.php.net to get a copy of this message | ||
By Jaxolotl Design
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.
The Strip_tags() is used to prevent tables or any other tag to be cut unproperly.
Enjoy :)
function reduce_text($string){
//Search the end of a word after [, int offset] and set the result as limit
$limit = strpos(strip_tags($string), " ",200);
//Change this number as you need
//Use $limit to replace width ...Text
return substr_replace(strip_tags($string), " ... <em>continue</em>",$limit);
//Change "<em>continue</em>" whith anithing you want
}
----
Server IP: 80.241.173.254
Probable Submitter: 151.44.188.108
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- https://master.php.net/note/edit/69823
Del: integrated -- https://master.php.net/note/delete/69823/integrated
Del: useless -- https://master.php.net/note/delete/69823/useless
Del: bad code -- https://master.php.net/note/delete/69823/bad+code
Del: spam -- https://master.php.net/note/delete/69823/spam
Del: non-english -- https://master.php.net/note/delete/69823/non-english
Del: in docs -- https://master.php.net/note/delete/69823/in+docs
Del: other reasons-- https://master.php.net/note/delete/69823
Reject -- https://master.php.net/note/reject/69823
Search -- https://master.php.net/manage/user-notes.php