Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Easy substr for paragraph in PHP
function substr_paragraph($string, $length = 520, $html = false) {
$pos = strpos($string, "</p>",$length);
$tag_len = 4;
$pos = strpos($string, "</div>",$length);
$tag_len = 5;
// No usable html found
$pos = $length-$tag_len;
$string = substr($string,0, $pos+$tag_len);
if($html != true){
$string = strip_tags($string);
return $string;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.