I have the following html page:
<!DOCTYPE html>
<html>
<head>
<title>Exemplo</title>
</head>
<body>
<div id="text">Valor 1</div>
<div id="text">Valor 2</div>
<div id="text">Valor 3</div>
</body>
</html>
I'm using the following function in PHP to get the text between a tag:
function capturar($string, $start, $end) {
$str = explode($start, $string);
$str = explode($end, $str[1]);
return $str[0];
}
Example usage:
<?php
$url = file_get_contents('http://localhost/exemplo.html');
$valor = capturar($url, '<div id="text">', '</div>');
echo $valor;
However, when you have more than one identical tag with different text between them, it only takes the text between the first tag.
What would I do to get all the texts between this (<div id="text">, </div>)
tag?