Get site name through link

0

//  IRIA PUXAR DO BANCO DE DADOS OS LINKS, MAS ASSIM JÁ DA UM EXEMPLO DE COMO IRIA FICAR.

$listalinks = "http://site1.com/embed1/CODIGO http://site2.com/embed2/CODIGO http://site3.com/embed3/CODIGO http://site4.com/embed4/CODIGO"; 

function pegaListadeUrlDaBase() {
 

   // Exemplo com links em uma única string da base, separados por ' ';
   $links_text = "$listalinks";
   return explode(" ", $links_text);
}

$urls = pegaListadeUrlDaBase();


foreach($urls as $url) {
   $nome = explode('.', parse_url($url, PHP_URL_HOST))[0];
   echo "<a href='$url'>$nome</a>";
}

I put it like this and it does not catch.

    
asked by anonymous 02.05.2018 / 13:13

3 answers

1

I believe this will work for you:

index.php

<form id="form" name="form" method="post" action="envia.php">
   Links: <label for="nome"></label>
          <textarea name="nome" id="nome" cols="20" rows="8"></textarea>
          <input type="submit" name="button" id="button" value="Enviar" />
</form>

<?php
include("conexao.php");

$sql = "SELECT seu_campo FROM sua_tabela";

$result = mysqli_query($conn, $sql);

while ($linha = mysqli_fetch_assoc($result)){

  echo "<a href=".$linha['nome'].">".$linha['nome']."</a><br>";
}
?>

In index.php , you enter the values in the textarea and then they are shown as a link just below, after insertion.

envia.php

<?php
include_once("conexao.php");

$nomes = $_POST['nome'];
$separar = explode("\n", $nomes);

foreach($separar as $nome){
    $query = "INSERT INTO sua_tabela (seu_campo) VALUES ('".$nome."')";
    $resultado = mysqli_query($conn, $query);
}

echo "Seu cadastro foi realizado com sucesso!";

?>

This is where all the magic of separating by breaking line using explode and then you can insert into the database.

connection.php

<?php
  $servidor = "localhost";
  $usuario = "root";
  $senha = "1234";
  $dbname = "teste";

  $conn = mysqli_connect($servidor, $usuario, $senha, $dbname);

?>

And this is the connection file I used, just change the value of the variables by your mysql data.

Finally, Replace where it says "your_table" and "your_field" for yours and I believe it will work quietly.

    
03.05.2018 / 20:18
1

You can use the php native function parse_url to retrieve information from a URL. This way:

$listalinks = "http://site1.com/embed1/CODIGO http://site2.com/embed2/CODIGO http://site3.com/embed3/CODIGO http://site4.com/embed4/CODIGO";

$urls = explode(" ", $listalinks);


foreach($urls as $url) {
   $nome = explode('.', parse_url($url, PHP_URL_HOST))[0];
   echo "<a href='$url'>$nome</a>";
}

This example will read:

<a href='http://site1.com/embed1/CODIGO'>site1</a>
<a href='http://site2.com/embed2/CODIGO'>site2</a>
<a href='http://site3.com/embed3/CODIGO'>site3</a>
<a href='http://site4.com/embed4/CODIGO'>site4</a>

See the documentation:

  

link

     

link

    
02.05.2018 / 13:35
-1
$ssite=('http://site.com'); 

$q=@file_get_contents($ssite); 

preg_match_all('#<title>([^<\/]{1,})<\/title>#i',$q,$match);

$otitle=($match[1][0]); 

echo $otitle; // Mostra frase do title
    
02.05.2018 / 13:29