Abdul Moiz Abdul Moiz - 2 months ago 13
PHP Question

Need to extract plain text from the string containing html entities and elements using php

$string = "<h2> <div class="OutlineElement Ltr SCX116040423" style="margin: 0px; padding: 0px; font-family: 'Segoe UI', Tahoma, Verdana, sans-serif; font-size: 8px; font-weight: normal;"> <p class="MsoNormal">Residents of the northeast are discovering that Branford Hall has become one of the fastest and most effective ways to begin a high growth career.<o:p>"

$string = preg_replace("/&#?[a-z0-9]+;/i","",$string);


I need the out as plain text:


Residents of the northeast are discovering that Branford Hall has become one of the fastest and most effective ways to begin a high growth career.


please help me in correcting the preg_replace regex?

Answer

PHP has some built-in functions that should be more convenient for this:

$string = strip_tags(html_entity_decode($string));
Comments