I have something like the following string (product description) outputted from a system (Magento):
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque sit amet leo ut metus commodo lacinia non sit amet lorem. Nam laoreet blandit eros quis rhoncus. Curabitur mi dolor, gravida vel lacinia in, pretium ut felis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Donec mollis vitae dolor eu viverra. Phasellus congue tortor ante, vel efficitur massa consectetur eu. Proin lacus nibh, vestibulum eu lectus sit amet, porttitor aliquet lorem. Ut tristique consectetur nulla in scelerisque. Mauris semper massa eu nisi rutrum consequat. Pellentesque vestibulum lacinia tellus, quis imperdiet orci hendrerit nec.
however I would like to get just the first x number of words, or up to the first paragraph (unfortunately the system we're using creates paragraphs by using double <br><br>
tags).
I have used this answer to create the following:
echo preg_replace( '/((\w+\W*){'.$numberOfWords.'}(\w+))(.*)/', '${1}', $processor->filter($description) );
However that does not account for paragraphs. I tried working an answer here into the above, unfortunately I couldn't get this to work (just returned the full untruncated string - likely down to my lack of regex ability!) Can anyone help me here?