I want to get several URLs shortened simultaneously, the next problem is that when I shorten them, the first URL is shortened correctly, but the others are shown like this: tinyurl.com/__urlqueacortas.url
and I get an error because it is a wrong address.
Below I put the used code:
Note:
tinyurl . com
appears separately, but it is not an error. It's because the Stack Overflow editor will not let me put it together if I want to post the question.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<form action="" method="post">
<textarea rows="20" name="urls" cols="40"><?= $_POST['urls'] ?></textarea>
<input id="submit" type="submit" name="submit" value="Acortar" class="btn-glow primary">
</form>
<?php
$enlace = $_POST['urls'];
$enlace2 = chop($enlace,'__'); // Elimina saltos de linea y espacio, pero solo al final de la cadena
$enlace3 = nl2br($enlace2); // Agregamos los saltos de linea <br />
$enlace4 = explode("<br />", $enlace3); // Creamos array con los datos recibidos
function acortar($link) {
$enlace5 = file_get_contents('http://tinyurl . com/api-create.php?url='.$link.''.$key.'');
return $enlace5;
}
foreach($enlace4 as $link){
echo acortar($link);
echo "<br>";
}