Convert text within a <div> into coded links!

Asked

Viewed 70 times

-2

I have a div that looks like this

<div class="tvshowlinks">
1
https://link1.com/qweeqweqw,https://segundolink.com/qweeqweqw.srt
https://link2.com/qweeqweqw,https://segundolink.com/qweeqweqw.srt
https://link3.com/qweeqweqw,https://segundolink.com/qweeqweqw.srt
https://link4.com/qweeqweqw,https://segundolink.com/qweeqweqw.srt

2
https://link1.com/qweeqweqw,https://segundolink.com/qweeqweqw.srt
https://link2.com/qweeqweqw,https://segundolink.com/qweeqweqw.srt
https://link3.com/qweeqweqw,https://segundolink.com/qweeqweqw.srt
https://link4.com/qweeqweqw,https://segundolink.com/qweeqweqw.srt
</div>

wanted to turn into something like below... is possible with php?

<?php
// codigo aqui 
?>

<div class="tvshowlinks">
<span>1ª temporada</span>
<a href="https://link1.com/qweeqweqw?legendas=https://segundolink.com/qweeqweqw.srt">Episódio 1</a>
<a href="https://link2.com/qweeqweqw?legendas=https://segundolink.com/qweeqweqw.srt">Episódio 2</a>
<a href="https://link3.com/qweeqweqw?legendas=https://segundolink.com/qweeqweqw.srt">Episódio 3</a>
<--!poderá ter mais de 24 episódios -->
<a href="https://link2.com/qweeqweqw?legendas=https://segundolink.com/qweeqweqw.srt">Episódio 24</a>

<span>2ª temporada</span>
<a href="https://link1.com/qweeqweqw?legendas=https://segundolink.com/qweeqweqw.srt">Episódio 1</a>
<a href="https://link2.com/qweeqweqw?legendas=https://segundolink.com/qweeqweqw.srt">Episódio 2</a>
<a href="https://link3.com/qweeqweqw?legendas=https://segundolink.com/qweeqweqw.srt">Episódio 3</a>
<--!poderá ter mais de 24 episódios -->
<a href="https://link3.com/qweeqweqw?legendas=https://segundolink.com/qweeqweqw.srt">Episódio 24</a>
</div>
  • You can use for in php to generate these links and number those episodes. !

1 answer

1

Assuming the links are relatively "followed", you can use a loop to generate the ending of each episode in sequence. See the following example:

var i;

for (i = 1; i < 30; i++) {

  //Declarando variáveis
  var a = document.createElement('a');
  var linha = document.createElement("BR");
  var link = document.createTextNode("Episodio " + i);

  //Aplicando funções e descrições do link
  a.appendChild(link);
  a.title = "Episodio " + i;
  a.href = "http://www.examplo.com/episodio/" + i;
  a.insertBefore(linha, a.nextSibling); //Aqui você vai adicionar a quebra de linha após cada resultado do loop
  document.body.appendChild(a); //Aqui você vai gerar os links com todas as configurações acima

}
<div id="links">
</div>

Browser other questions tagged

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