<?php
function pesquisarStrpos($palheiro, $agulha, $pesquisa) {
$count = 0;
$pos = -1;
do {
$pos = strpos($palheiro, $agulha, $pos + 1); $count++;
} while ($pos !== false && $count < $pesquisa);
return $pos;
}
$texto="<p>primeiro paragrafo</p><p>segundo paragrafo</p><p>terceiro paragrafo</p>";
$pos = (pesquisarStrpos($texto, '</p>', 2));
$textoInicio=substr($texto,0,$pos+4);
$result=$textoInicio."<div>...</div>".$textoFim;
echo $result;
PD9waHAKCmZ1bmN0aW9uIHBlc3F1aXNhclN0cnBvcygkcGFsaGVpcm8sICRhZ3VsaGEsICRwZXNxdWlzYSkgewogICAgJGNvdW50ID0gMDsKICAgICRwb3MgPSAtMTsKICAgIGRvIHsKICAgICAgICAkcG9zID0gc3RycG9zKCRwYWxoZWlybywgJGFndWxoYSwgJHBvcyArIDEpOwogICAgICAgICRjb3VudCsrOwogICAgfSB3aGlsZSAoJHBvcyAhPT0gZmFsc2UgJiYgJGNvdW50IDwgJHBlc3F1aXNhKTsKICAgIHJldHVybiAkcG9zOwp9CiAKJHRleHRvPSI8cD5wcmltZWlybyBwYXJhZ3JhZm88L3A+PHA+c2VndW5kbyBwYXJhZ3JhZm88L3A+PHA+dGVyY2Vpcm8gcGFyYWdyYWZvPC9wPiI7CiAKJHBvcyA9IChwZXNxdWlzYXJTdHJwb3MoJHRleHRvLCAnPC9wPicsIDIpKTsKIAokdGV4dG9JbmljaW89c3Vic3RyKCR0ZXh0bywwLCRwb3MrNCk7CiAKJHRleHRvRmltPXN1YnN0cigkdGV4dG8sJHBvcys0LHN0cmxlbigkdGV4dG8pKTsKIAokcmVzdWx0PSR0ZXh0b0luaWNpby4iPGRpdj4uLi48L2Rpdj4iLiR0ZXh0b0ZpbTsKCmVjaG8gJHJlc3VsdDs=