|
Posted by crucialmoment on 03/25/06 23:22
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>";
}
Navigation:
[Reply to this message]
|