Hello,
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;
But when I have more than one identical tag with different text between them, it only takes the text between the first tag, what I would do to get all the texts between that tag ( <div id="text">
, </div>
) and to add them to an array?
Thank you in advance.