I'm trying to get data from an online page only that the code is having a problem, it can not process all items in POST
mode, within foreach
.
Even if I put the items in the list, just get the last item posted. I would like to know 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>