The code below shows the first paragraph of a string, but I'd like it to show the first three paragraphs:
preg_match("/<p>(.*)<\/p>/",$paragraphs,$matches);
echo $matches[0];
I'm new to regular expressions, so I've been struggling to figure this out. Any ideas?
Thanks for your help.
You can use preg_match_all:
preg_match_all("/<p>(.*)<\/p>/", $paragraphs, $matches);
echo $matches[0][0];
echo $matches[0][1];
echo $matches[0][2];
When you use preg_match_all, each subarray in $matches gains a new entry for each match.
See php.net/manual/en/function.preg-match-all.php for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With