Skip to content

Instantly share code, notes, and snippets.

@pvphong90
Created December 8, 2017 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvphong90/d0c1a1a1700d07e085f3c99c1caa0f07 to your computer and use it in GitHub Desktop.
Save pvphong90/d0c1a1a1700d07e085f3c99c1caa0f07 to your computer and use it in GitHub Desktop.
function count_p( $insertion, $paragraph_id, $content ) {
$end_p = '</p>';
$paragraphs = explode( $end_p, $content );
foreach ($paragraphs as $index => $paragraph) {
if ( trim( $paragraph ) ) {
$paragraphs[$index] .= $end_p;
}
if ( $paragraph_id == $index + 1 ) {
$paragraphs[$index] .= $insertion;
}
}
return implode( '', $paragraphs );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment