-
-
Save lordhasyim/51fe423192cd6ef09fbdc993b24ab588 to your computer and use it in GitHub Desktop.
PHP get first paragraph from a string function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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