note 87533 added to function.wordwrap

From: Date: Tue, 09 Dec 2008 13:09:27 +0000
Subject: note 87533 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-147949@lists.php.net to get a copy of this message
<?php function substr_word($str, $start, $end) { //function taking sub string from $str in between $start chars and $end chars. $String = wordwrap($str, $end, '[cut]', false); //add [cut] for each word after $end chars $ExplodedString = explode('[cut]', $String); //make an array with elements long for $end chars $end=ceil(strlen($text)/$end); //how many elements of array are there. (celi > round >floor) $i=floor($end/$start); //take an element with start position $String = $ExplodedString[$i]; if ($String[0]==" ") { substr($String, 1); } if ($String[0]==" ") { substr($String, 1); } if ($String[0]==" ") { substr($String, 1); } return $String; } ?> Usage example: <?php $from=strpos($text,$word)-100; $to=strpos($text,$word)+400; $text=substrpos($text, $from, $to); ?> will return text 100 chars before and 400 chars after searched word without breaking the words in text. Good for seach scirpts for your website - imagine that $word is keyword you search for. ---- Server IP: 82.160.94.10 Probable Submitter: 78.8.13.84 ---- Manual Page -- http://www.php.net/manual/en/function.wordwrap.php Edit -- https://master.php.net/note/edit/87533 Del: integrated -- https://master.php.net/note/delete/87533/integrated Del: useless -- https://master.php.net/note/delete/87533/useless Del: bad code -- https://master.php.net/note/delete/87533/bad+code Del: spam -- https://master.php.net/note/delete/87533/spam Del: non-english -- https://master.php.net/note/delete/87533/non-english Del: in docs -- https://master.php.net/note/delete/87533/in+docs Del: other reasons-- https://master.php.net/note/delete/87533 Reject -- https://master.php.net/note/reject/87533 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#147949) next »