PHP Extracting Text From Html Tags – String Function

<?php
$html = file_get_contents('example.html');
preg_match_all('@<(strong|em)>(.+?)</\1>@is', $html, $matches);
foreach ($matches[2] as $text) {
    print "Text: $text \n";
}
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.