1
I’m trying to get data from an online page only the code is presenting a problem, it can not process all items in the way POST
, within the foreach
.
Even if I put the items in list only takes the last item posted. I wonder how I can solve this problem.
Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form id="form1" name="form1" method="post" action="pegavideo.php">
<p>
<textarea name="urls" id="urls" cols="100" rows="20"></textarea>
</p>
<p>
<input type="submit" name="gerar" id="gerar" value="Gerar urls do Super Animes" />
</p>
</form>
<?php
function pegarDados ($valorUrl) {
$url = $valorUrl;
$html = file_get_contents($url);
$doc = new DOMDocument();
@$doc->loadHTML($html);
$tags = $doc->getElementsByTagName('source');
foreach ($tags as $tag) { return $tag->getAttribute('src').'<br/>';}
}
$dados = $_POST['urls'];
$valoresUrl = explode("\n",$dados);
for($i = 0; $i < count($valoresUrl); $i++) {
echo pegarDados($valoresUrl[$i]);
}
?>
</body>
</html>
You are taking the n with the Trim and trying to make the explode with an n that you removed earlier
– Jorge Costa
Ready corrected that part you mentioned.
– Rob
What error you are receiving
– Jorge Costa
What is happening and the following, if I put a list of links, only returns a single result. That is if I put for example 10 links only returns a single url.
– Rob
Make a $valoresUrl print_r to see what’s on for
– Jorge Costa
I put the numbers 1,2,3 to the test and gave this result Array ( [0] => 1 [1] => 2 [2] => 3 ) Array ( [0] => 1 [1] => 2 [2] => 3 ) Array ( [0] => 1 [1] => 2 [2] => 3 )
– Rob
Try putting 3 URL separated by enter which gives the print_r
– Jorge Costa
Array ( [0] => https://drive.google.com/1 [1] => https://drive.google.com/2 ) Array ( [0] => https://drive.google.com/1 [1] => https://drive.google.com/2 ) Literally repeating the same result.
– Rob