Détection de lien html

Résolu
info1121 Messages postés 19 Statut Membre -  
info1121 Messages postés 19 Statut Membre -
Bonjour, j'ai une page web ' demande d'inscription ' avec un champ commentaires.
Cela fait presque 20 ans sans problèmes, mais depuis quelques mois je recois pleins de demandes avec des liens html ( genre sexe ou autre ) dans le champ commentaires.
Ma question est comment faire pour détecter un lien html

if($msg == @(http://www[^ ]+)@){
echo 'Votre demande est refusé ';
echo '<a href="../index.php">accueil</a>';

}else{
Désolé pour la syntaxe, je trouve pas comment faire

Merci de votre aide

1 réponse

  1. jordane45 Messages postés 30426 Date d'inscription   Statut Modérateur Dernière intervention   4 830
     
    Bonjour,

    Il te suffit d'utiliser une expression regulière ( REGEX )
    https://www.catswhocode.com/blog/15-php-regular-expressions-for-web-developers
    0
    1. info1121 Messages postés 19 Statut Membre
       
      Bonjour, quelquechose comme ca


      if (preg_match('/^(http|https|ftp)://([A-Z0-9][A-Z0-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?/?/i', $msg)) {
      echo 'Votre demande est refusée ';
      echo '<a href="../index.php">accueil</a>';

      }else{

      $msg est ce que retourne le commentaire.
      Cela ne fonctionne pas

      Merci de ton aide
      0
    2. jordane45 Messages postés 30426 Date d'inscription   Statut Modérateur Dernière intervention   4 830
       
      <?php
      
      // The Regular Expression filter
      $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
      
      // The Text you want to filter for urls
      $text = "The text you want to filter goes here. http://google.com";
      
      // Check if there is a url in the text
      if(preg_match($reg_exUrl, $text, $url)) {
      
             // make the urls hyper links
             echo preg_replace($reg_exUrl, "<a href="{$url[0]}">{$url[0]}</a> ", $text);
      
      } else {
      
             // if no urls in the text just return the text
             echo $text;
      
      }
      ?>
      
      0
    3. info1121 Messages postés 19 Statut Membre
       
      Merci, problème résolu

      // The Regular Expression filter
      $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";


      // Check if there is a url in the text
      if(preg_match($reg_exUrl, $msg)) {

      echo 'Votre demande est refusée ';
      echo '<a href="../index.php">accueil</a>';

      }else{
      0