<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title>Convertisseur de noms et URL</title>
    </head>
    <body>
        <h1>Convertisseur</h1>
        
        Copier coller une liste de noms et d'URL séparés par une tabulation.
        
        <textarea cols="60" rows="10">
            <?php
       $post = '';
        if( isset($_POST['texte']) && $_POST['texte'] != null ){ 
            $post = $_POST['texte'];
            $boom = explode("\n"  , $post);
            $retour ='';
//            var_dump($boom);
            foreach ($boom as $k => $v) {
                $ligne = explode("\t" , $v);
                $url = $ligne[1];
                $nom = $ligne[0];
                if( !strpos($url, '.')){
                    
                $retour .= $nom;
                }
                else{
                   $retour .='<a href="'.$url.'">'.$nom."</a>"; 
                }
                
            }
            
            $links = nl2br($retour);
            $retour = htmlentities($retour);
          echo "$retour " ;  
        }
        
        ?>
        </textarea>
        <hr/>
        <?php 
        echo "$links ";
        ?>
        
        <form action="" method="POST">
            <textarea name="texte" id="texte" cols="60" rows="10">
                <?php
            echo "$post" ; 
        // put your code here
        ?></textarea>
            <input type="submit" value="envoyer"/>
        </form>
        
    </body>
</html>
