1
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 PHP function to pick up the text between a tag:
function capturar($string, $start, $end) {
$str = explode($start, $string);
$str = explode($end, $str[1]);
return $str[0];
}
Example of use:
<?php
$url = file_get_contents('http://localhost/exemplo.html');
$valor = capturar($url, '<div id="text">', '</div>');
echo $valor;
However, when there is more than one identical tag with the text between them different, it only picks up the text between the first tag, what would I do to pick up all texts between that tag (<div id="text">
, </div>
) and add them between an array?
Thanks in advance.
Look
id
is a unique identifier, can not repeat on the same page– MagicHat