Bhaamb Bhaamb - 1 year ago 101
PHP Question

PHP - preg_match unable to get all elements from html url

I have been trying to get the innertext of html tag from a url ( but i get only 1 output. The code i tried is:

$html = file_get_contents("");
preg_match("'<h3>(.*?)<h3>'si", $html, $match);

even when i try to use foreach or i try to use $match[2], it does not work. Any help would certainly be appreciated.


Answer Source

you need preg_match_all function. Documented here

try like this.

$html = file_get_contents("");
preg_match_all('/<h3>(.*?)<h3>/si', $html, $match);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download