Skip to content

Instantly share code, notes, and snippets.

@lordhasyim
Forked from a9un9hari/paragraphFunction.php
Created June 18, 2019 03:59
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 lordhasyim/51fe423192cd6ef09fbdc993b24ab588 to your computer and use it in GitHub Desktop.
Save lordhasyim/51fe423192cd6ef09fbdc993b24ab588 to your computer and use it in GitHub Desktop.
PHP get first paragraph from a string function
<?php
function getFirstPara($string){
$string = substr($string,0, strpos($string, "</p>")+4);
return $string;
}
// If you wanted to remove the paragraph tags from the HTML
function getFirstPara2($string){
$string = substr($string,0, strpos($string, "</p>")+4);
$string = str_replace("<p>", "", str_replace("<p/>", "", $string));
return $string;
}
// Then call the function, passing the string variable
echo getFirstPara($HTMLString);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment