| 
	
 | 
 Posted by d on 06/15/22 11:43 
"crucialmoment" <crucialmoment@gmail.com> wrote in message  
news:1143321725.586625.135020@g10g2000cwb.googlegroups.com... 
> Greetings, 
> I am trying to automatically pull a beginning section from submitted 
> text and return it with a More.. link. The submitted text is in html 
> created by FckEditor (http://www.fckeditor.net/). 
> The trouble I am running into is the cutoff point is often inside of a 
> tag - ie after an opening <div> but the closing div is cut. 
> The only idea I have come up with is to build an array of all possible 
> html tags and search for a close for each but I am hoping there is a 
> cleaner method. Has anyone attempted such a feat previously? 
> 
> function getSynop($input="", $more_link="", $synop_size='750') { 
>   $tmp_str = substr($input, 0, $synop_size); 
>   $end_val = strrpos($tmp_str, ">") + 1; 
>   if($end_val < ($synop_size)) { 
>   $end_val = strrpos($tmp_str, ".") + 1; 
>   } 
>   if($end_val < ($synop_size)) { 
>   $end_val = strrpos($tmp_str, ">") + 1; 
>   } 
>   Return substr($input, 0, $end_val) ." <a 
> href='$more_link'>more...</a>"; 
> } 
> 
 
1.  Get text. 
2.  Remove tags 
3.  Take first <n> characters. 
 
$text="This is some <div>text</div> isn't it interesting.  <b>send  
money.</b>  <i>and beer</i>"; 
 
function getSynop($input="", $more_link="", $synop_size=750) { 
    $syn=substr(strip_tags($text), 0, $synop_size); 
    return $syn." <a href='".$more_link.."'>more...</a>"; 
} 
 
hope that helps! 
 
dave
 
  
Navigation:
[Reply to this message] 
 |