Loop process error using for

Asked

Viewed 40 times

0

Hello I would like the help of you, to try to solve the following problem, I created a script that allows to take the direct link of an online video upload host, the process works, but I do not know why the loop of repetition is not working. When I place several links only and generated the first link of the listing.

I would like your help to correct this mistake.

Follow my code below.

<!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="links.php">
  <p>
    <textarea name="url" cols="100" rows="20" id="urls"></textarea>
  </p>
  <p>
    <input type="submit" name="gerar" id="gerar" value="Gerar urls de Link direto" />
  </p>
</form>

<?php 
$dados = $_POST['url'];

// Aplicva os parametros de Explode para contar os itens
$url1 = count(explode("/n", $dados));
$url2 = array_map('trim', explode("/n", $dados));

// Verifica se o valor total e subtrai caso seja maior que 1 para fazer o loop perfeitamente
if ($url1 > 1) { $soma = $url1 -1; } 

echo '<textarea cols="200" rows="20" id="input">';

// Aplica for colocando o valor total de links para fazer o loop
for ($i = 0; $i <= $soma; $i++) { 

// Caso seja menor que a soma aplica quebra de linha
if ($i < $soma) {

// Aplica a aparição da url e codifica para aparecer a url de link direto com quebra de linha
$dados = $url2[$i];
$url3 = explode('/', $dados);
$aniteca = 'https://meusite.com/?v='.$url3[5];
$html = file_get_contents($aniteca);
$valor1 = explode("'720p':[{'type':", $html);
$valor1 = explode("mp4'}],", $valor1[1]);
$valor1 = explode("'video/mp4', 'src': '", $valor1[0]);
echo $valor1[1].'mp4'."\n";



} else { 

// Aplica a aparição da url e codifica para aparecer a url de link direto sem quebra de linha
$dados = $url2[$i];
$url3 = explode('/', $dados);
$aniteca = 'https://meusite.com/?v='.$url3[5];
$html = file_get_contents($aniteca);
$valor1 = explode("'720p':[{'type':", $html);
$valor1 = explode("mp4'}],", $valor1[1]);
$valor1 = explode("'video/mp4', 'src': '", $valor1[0]);
echo $valor1[1].'mp4';

}
}
echo '</textarea>';
?>
<br/>
<button id="copy-button">Copiar todos as urls</button>
<script>
    var input  = document.getElementById("input");
    var button = document.getElementById("copy-button");

    button.addEventListener("click", function (event) {
        event.preventDefault();
        input.select();
        document.execCommand("copy");
    });
</script>
</body>
</html>
  • This variable $dados who receives from $_POST is a single string? Usually $_POST comes with an array of data. What might imply in this line break logic $url1 = count(explode("/n", $dados));Give a print_r($_POST) and see how the data is allocated to make sure you’re doing the right treatment.

  • Yes and only, and generated this result 'Array ( [url] => https://meusite.com/display/2703/28489/-06 https://meusite.com/display/2706/28486/-06 [generate] => Generate Link urls direct from meusite ) '

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.