Détection de lien html

Résolu/Fermé
info1121 Messages postés 19 Date d'inscription dimanche 17 mars 2013 Statut Membre Dernière intervention 1 juin 2019 - 13 janv. 2019 à 14:55
info1121 Messages postés 19 Date d'inscription dimanche 17 mars 2013 Statut Membre Dernière intervention 1 juin 2019 - 13 janv. 2019 à 17:35
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
A voir également:

1 réponse

jordane45 Messages postés 38393 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 24 janvier 2025 4 731
13 janv. 2019 à 15:25
Bonjour,

Il te suffit d'utiliser une expression regulière ( REGEX )
https://www.catswhocode.com/blog/15-php-regular-expressions-for-web-developers
0
info1121 Messages postés 19 Date d'inscription dimanche 17 mars 2013 Statut Membre Dernière intervention 1 juin 2019
13 janv. 2019 à 16:26
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
jordane45 Messages postés 38393 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 24 janvier 2025 4 731
13 janv. 2019 à 16:50
<?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
info1121 Messages postés 19 Date d'inscription dimanche 17 mars 2013 Statut Membre Dernière intervention 1 juin 2019
13 janv. 2019 à 17:35
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