1
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 takes the text between the first tag.
What I would do to get all texts between that tag (<div id="text">, </div>)
?
Using regex you could achieve something much more precise.
– Edilson
It is highly recommended not to change the question, and there is an answer to that. Ask a new question if you have another question.
– Don't Panic
Pedro, if you have other questions, open a new question, but do not edit by completely changing an existing one, especially when there are already answers. Incidentally, you’ve already asked for it here. Take the [tour] to understand how the site works.
– Woss