Programmation

Mardi 17 janvier 2012 2 17 /01 /Jan /2012 21:21

<?php

function findHttp($texte, $image = true, $video = true) {
    $order = array("\r\n", "\n", "\r");
    $texte = str_replace($order, " <br/> ", htmlspecialchars(stripslashes($texte)));   
   
    $patterns = array ("/(http|https):\/\/(\w{3}\.{1}|\w{0}\.{0})[A-Za-z0-9_\-\.]+(\.[A-Za-z]{2,4}\/){1}(.)+(\.jpg|\.jpeg|\.png|\.gif)/is",
                       "/(http|https):\/\/(\w{3}\.{1}|\w{0}\.{0})(megavideo\.com\/\?v=(.){8,}|youtube\.com\/watch\?v\=(.){11,}){1}/is",
                       "/(http|https):\/\/(\w{3}\.{1}|\w{0}\.{0})[A-Za-z0-9_\-\.]+(\.[A-Za-z]{2,4}(\/)?){1}(.)*/is");
    $texteExplode = explode(" ", $texte);
    foreach ($texteExplode as $key => $mot) {
        if (preg_match_all($patterns[0], $mot, $matchs, PREG_SET_ORDER)) {
            if ($image)
                $texteExplode[$key] = str_replace($matchs[0][0], "<img src='" . $matchs[0][0] . "' style='max-width:80%' />", $texteExplode[$key]);
            else
                $texteExplode[$key] = str_replace($matchs[0][0], "<a href='" . $matchs[0][0] . "' target='_blank'>" . $matchs[0][0] . "</a>", $texteExplode[$key]);
        }
        else if (preg_match_all($patterns[1], $mot, $matchs, PREG_SET_ORDER)) {
            if ($video) {
                $src = str_replace("/?v=", "/v/", str_replace("/watch?v=", "/v/", $matchs[0][0]));
                $texteExplode[$key] = str_replace($matchs[0][0], "<embed src='" . $src . "' type='application/x-shockwave-flash' width='100%' height='415px' allowscriptaccess='always' allowfullscreen='true'></embed>", $texteExplode[$key]);
            } else
                $texteExplode[$key] = str_replace($matchs[0][0], "<a href='" . $matchs[0][0] . "' target='_blank'>" . $matchs[0][0] . "</a>", $texteExplode[$key]);
        }
        else if (preg_match_all($patterns[2], $mot, $matchs, PREG_SET_ORDER)) {
            $texteExplode[$key] = str_replace($matchs[0][0], "<a href='" . $matchs[0][0] . "' target='_blank'>" . $matchs[0][0] . "</a>", $texteExplode[$key]);
        }
    }
   
    return implode(" ", $texteExplode);
}

 

// Ex


$str = "Lien http : http://agd243.over-blog.com/ \n Video : http://www.youtube.com/watch?v=ke8ZSi80j_0 \n Image : http://www.google.mu/images/nav_logo101.png \n Merci a agd243 ;-)";


echo findHttp($str, true, true);
?>

 

Merci de commenter ce poste.

Par agd243 - Publié dans : Programmation - Communauté : Progghub
Ecrire un commentaire - Voir les 0 commentaires
Mardi 17 janvier 2012 2 17 /01 /Jan /2012 20:58

<?php

function findHref($texte)
{
    $order = array("\r\n", "\n", "\r");
    $texte = str_replace($order, " <br/> ", htmlspecialchars(stripslashes($texte)));   
   
    $texteExplode = explode(" ", $texte);
    foreach ($texteExplode as $key => $mot)
        if (preg_match_all("/(http|https):\/\/(\w{3}\.{1}|\w{0}\.{0})[A-Za-z0-9_\-\.]+(\.[A-Za-z]{2,4}(\/)?){1}(.)*/is", $mot, $matchs, PREG_SET_ORDER))
            $texteExplode[$key] = str_replace($matchs[0][0], "<a href='" . $matchs[0][0] . "' target='_blank'>" . $matchs[0][0] . "</a>", $texteExplode[$key]);
           
    return implode(" ", $texteExplode);
}

 

//Ex :

 

$str = "le blog le plus cool c'est http://agd243.over-blog.com/  ! \n Et merci a agd243 :-)";
echo findHref($str);

?>

A noter qui existe une autre fonction qui permet de trouver des liens d'image ou video Youtube | Megavideo automatiquement. Ici Php : Fonction pour trouver les liens dans une chaine de carateres.

 

Merci de commenter ce poste.

Par agd243 - Publié dans : Programmation - Communauté : Progghub
Ecrire un commentaire - Voir les 0 commentaires
Mardi 17 janvier 2012 2 17 /01 /Jan /2012 20:16

Bonjour a tous, voila je vous présente un plugins de jQuery qui permet d'avoir un chatbox un peu comme celle de Facebook. Pour le moment le plugins n'est pas trés stable cause il y a encore des modifications a faire. Sachez qui j'y travaille déjà sur l'amélioration du plugins et qu'un nouveau version sera disponible très bientot.

 

Instruction : Veuillez d'abord creer une base de donnees : chatbox. Puis executer le fichier index.php depuis localhost.

Pour faire marcher le plugins l'element doit avoir les attributs suivantes :

  1. id : user_(id)
  2. userid : (id)
  3. username : (noms)

Id : l'id de lutilisateur qui est en ligne et qui != vous.

Noms : le noms de l'utilisateur en ligne et != vous.

 

Merci de télécharger le plugins ici : Megaupload : http://www.megaupload.com/?d=WA6EMTAP

 

Et n'oubliez pas que c'est pas toujours trés stable. Merci de commenter pour plus d'info.

Par agd243 - Publié dans : Programmation - Communauté : Progghub
Ecrire un commentaire - Voir les 1 commentaires
Mardi 17 janvier 2012 2 17 /01 /Jan /2012 20:02

Fichier requis : Jquery.latest.js

Utilisation : $("textarea").ajusttextarea(hauteur_minimale_du_textarea, hauteur_des_lignes);

 

jQuery.fn.ajusttextarea = function(minheight, lineheight) {
        return this.each(function() {
            object = $(this);
            $(this).css("overflow","hidden");
            $(this).css("resize","none");
            $(this).attr("wrap","hard");
            $(this).animate({height: minheight }, 200);
           
            $(this).keyup(function(e) {
                if ($(this).prop("scrollHeight") > minheight) {
                    if (e.keyCode == 8 || e.keyCode == 46) {
                        $(this).height($(this).prop("scrollHeight") - lineheight);
                        $(this).height($(this).prop("scrollHeight"));
                    } else if (e.ctrlKey || e.keyCode == 13)
                        if ($(this).prop("scrollHeight") > $(this).height())
                            $(this).animate({height: $(this).prop("scrollHeight") }, 200);
                }
            });
        });
    };

 

Pour tous question merci de commenter le poste.

Par agd243 - Publié dans : Programmation - Communauté : Progghub
Ecrire un commentaire - Voir les 0 commentaires
 
Créer un blog gratuit sur over-blog.com - Contact - C.G.U. - Rémunération en droits d'auteur - Signaler un abus - Articles les plus commentés