Remplacer une toutes les occurences d'une variable dans une chaine de caractere

angellestat Messages postés 4 Date d'inscription vendredi 25 janvier 2008 Statut Membre Dernière intervention 27 novembre 2010 - 27 nov. 2010 à 01:00
cod57 Messages postés 1653 Date d'inscription dimanche 7 septembre 2008 Statut Membre Dernière intervention 11 septembre 2013 - 27 nov. 2010 à 07:52
Bonjour à tous,
Je suis entrain de développer un petit forum sur un site. Il propose des zones de commentaire dans lesquelles les utilisateurs peuvent poster . Je voudrais remplacer toutes les occurrences des adresses web en liens actifs:
exemple:
si l'utilisateur saisi:"j'ai posté sur www.phpcs.com" on retourne "j'ai posté sur www.phpcs.com " ceci pour toutes les occurences.

la fonction str_replace peut le faire mais partiellement, parcequ'elle ne remplace toutes les d'une chaine fixe( invariable) dc là je suis perdu.

j'ai pensé au preg_match("#^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$#", $chaine)
mais je suis confu.

j'espere au moins avoir ete assez explicite par rapport à mon probleme
merci

ps: je voudrais pas utiliser de bbcode ni de classe ckeditor ca doit etre auto.

1 réponse

cod57 Messages postés 1653 Date d'inscription dimanche 7 septembre 2008 Statut Membre Dernière intervention 11 septembre 2013 19
27 nov. 2010 à 07:52
Bonjour
j'ai ça dans mes favoris
a++

/*http://www.wallpaperama.com/forums/how-to-make-clickable-text-url-links-from-text-links-change-to-clicking-t641.html*/
<?php 
http://www.wallpaperama.com/forums/how-to-make-clickable-text-url-links-from-text-links-change-to-clicking-t641.html
function clickable_link($text) 
{ 
# this functions deserves credit to the fine folks at phpbb.com 

$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); 

// pad it with a space so we can match things at the start of the 1st line. 
$ret = ' ' . $text; 

// matches an "xxxx://yyyy" URL at the start of a line, or after a space. 
// xxxx can only be alpha characters. 
// yyyy is anything up to the first space, newline, comma, double quote or < 
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<< Go Back 

 
PHP Hosting by Webune.com 

 
 
 
0
Rejoignez-nous