Tags
PHP , HTML
Asked 3 years ago
9 Jul 2021
Views 752
Estelle

Estelle posted

How to extract text between HTML tags in PHP

How to extract text between HTML tags in PHP
Nilesh

Nilesh
answered Feb 17 '22 00:00

suppose you want extract text between span tag code will in php as below :


$html='<span class="a-size">Html goes here</span>';
 $spantag = '/<span class="a-size">(?P<val>[^>]*)<\/span>/';
 preg_match_all($spantag,$html,$text);
print_r($text);

preg_match_all will extract text between span tag by regex .
it will print text between all span tag in html




Post Answer