<?php
$str = 'Hello :oD je cherche l\'amour de ma vie :oP !';
$recherche = array(':oD', ':oP');
$remplace = array('<img src="smiley1.gif"/>', '<img src="smiley2.gif"/>');
echo str_replace($recherche, $remplace, $str);
/*
Hello <img src="smiley1.gif"/> je cherche l'amour de ma vie <img src="smiley2.gif"/> !
*/
?><?php
// pour l'exemple, je stocke la phrase dans une variable que j'appelle $str
$str = 'Hello :oD je cherche l\'amour de ma vie :oP !';
// la phrase peut très bien venir d'un fichier texte, d'une base de donnée, d'un formulaire html, etc...
// INFO sur les variables: http://fr.php.net/manual/fr/language.types.string.php
// Je stocke dans un array (tableau) les symboles représentant un smiley
// INFO sur les array:
// http://fr.php.net/manual/fr/language.types.array.php
$recherche = array(':oD', ':oP');
// Je stocke dans un array (tableau) les images qui remplaceront les symboles par une image
// INFO sur les array:
// http://fr.php.net/manual/fr/language.types.array.php
$remplace = array('<img src="smiley1.gif"/>', '<img src="smiley2.gif"/>');
// A noter que l'image smiley1.gif remplacera le premier élement du tableau $recherche, ainsi de suite
// str_replace -- Remplace toutes les occurrences dans une chaîne
// INFO: http://fr3.php.net/str_replace
echo str_replace($recherche, $remplace, $str);
/*
Hello <img src="smiley1.gif"/> je cherche l'amour de ma vie <img src="smiley2.gif"/> !
*/
?> Pas de panique, en procédant par étape, tu pourras comprendre facilement.help help help
<?php
require_once("phplib/connect.php");
require_once("phplib/requete.class.php");
require_once("phplib/lib.php");
session_start();
if (!isset($_SESSION['id_membre'])) header("location: redirinscr.html");
$visiteur = $_SESSION['id_membre'];
$membrefiche = $_GET['id'];
$sqlvip = "SELECT vip FROM tem_membres WHERE id_membre='$visiteur'";
$result = mysql_query($sqlvip, $link) or die($sqlvip."<br/>".mysql_error());
while($row=mysql_fetch_assoc($result)) {
$limitevip = $row['vip'];
}
mysql_free_result($result);
$diff = diff2date(date("Y-m-d"), $limitevip);
if ($diff['jours'] < 0) header("location: redirvip.html");
if (!empty($_POST)) {
$sqlmessage = new requete("INSERT", "poste de message");
foreach($_POST as $key=>$value) {
if($key=="titre" && $value=="") $value = "Sans titre";
$sqlmessage->addChampValeur("tem_messages", $key, addslashes(htmlentities($value)));
}
if ($sqlmessage->execute($link)) {
header("location: fiche.php?id=$membrefiche");
} else {
die($sqlmessage->erreur);
}
}
$sqlpseudo = "SELECT pseudo FROM tem_membres WHERE id_membre='$membrefiche'";
$result = mysql_query($sqlpseudo, $link) or die($sqlpseudo."<br/>".mysql_error());
while($row=mysql_fetch_assoc($result)) {
$pseudo = stripslashes($row['pseudo']);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- Début HEADER --><HTML><HEAD><TITLE>temple du plaisir (rencontre)</TITLE><LINK
href="message envoyer_fichiers/style.css" rel=stylesheet>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<STYLE type=text/css>BODY {
BACKGROUND-COLOR: #FFFFFF}
.Style3 {
FONT-WEIGHT: bold; COLOR: #ff0099
}
.Style6 {
COLOR: #000000
}
.Style7 {
FONT-WEIGHT: bold; COLOR: #000000; FONT-STYLE: italic
}
.Style8 {
FONT-SIZE: 16px
}
.Style14 {
FONT-SIZE: 14px; COLOR: #666666
}
.Style15 {
FONT-WEIGHT: bold; FONT-SIZE: 14px; FONT-STYLE: italic
}
</STYLE>
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY class=back0 leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
<CENTER><BR>
<TABLE height=619 cellSpacing=0 cellPadding=0 width=777 border=0>
<TBODY>
<TR>
<TD class=bg vAlign=top width=777 height=82><IMG height=82 alt=banniere
src="images/banniere2.jpg" width=767></TD>
</TR>
<TR>
<TD height=537><!-- fin HEADER --><!-- cellule pour votre contenu : début -->
<TABLE cellSpacing=0 cellPadding=0 width=770 border=0>
<TBODY>
<TR>
<TD width=3 height=489><IMG height=1
src="message envoyer_fichiers/clear.gif" width=3></TD>
<TD class=bg1 width=8><IMG height=1
src="message envoyer_fichiers/clear.gif" width=8></TD>
<TD class=bg1 width=748>
<TABLE cellSpacing=0 cellPadding=0 width=748 border=0>
<TBODY>
<TR>
<TD class=txt0>
<DIV class=Style6 align=left>
<DIV align=center>Ils nous rejoignent cette semaine :
</DIV></DIV></TD></TR>
<TR>
<TD><IMG height=10 src="message envoyer_fichiers/clear.gif"
width=1></TD></TR>
<TR>
<TD align=middle>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD class=bg2><IMG height=50 hspace=2
src="images/1.jpg" width=50
vspace=2></TD>
<TD><IMG height=1
src="message envoyer_fichiers/clear.gif" width=5></TD>
<TD class=bg2><IMG height=50 hspace=2
src="images/2.jpg" width=50
vspace=2></TD>
<TD><IMG height=1
src="message envoyer_fichiers/clear.gif" width=5></TD>
<TD class=bg2><IMG height=50 hspace=2
src="images/3.jpg" width=50
vspace=2></TD>
<TD><IMG height=1
src="message envoyer_fichiers/clear.gif" width=5></TD>
<TD class=bg2><SPAN class=txt0><IMG height=50 hspace=2
src="images/6.jpg" width=50
vspace=2></SPAN></TD>
<TD><IMG height=1
src="message envoyer_fichiers/clear.gif" width=5></TD>
<TD class=bg2><IMG height=50 hspace=2
src="images/8.jpg" width=50
vspace=2></TD>
<TD><IMG height=1
src="message envoyer_fichiers/clear.gif" width=5></TD>
<TD class=bg2><IMG height=50 hspace=2
src="images/7.jpg" width=50
vspace=2></TD>
<TD><IMG height=1
src="message envoyer_fichiers/clear.gif" width=5></TD>
<TD class=bg2><IMG height=50 hspace=2
src="images/5.jpg" width=50
vspace=2></TD>
<TD><IMG height=1
src="message envoyer_fichiers/clear.gif" width=5></TD>
<TD class=bg2><IMG height=50 hspace=2
src="images/4.jpg" width=50
vspace=2></TD>
</TR></TBODY></TABLE></TD></TR>
<TR>
<TD align=middle>
<DIV class=Style3 align=right>
<DIV align=left></DIV></DIV></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=748 border=0>
<TBODY>
<TR>
<TD width=15> </TD>
<TD width=718> </TD>
<TD width=15> </TD>
</TR>
<TR>
<TD background="" height=274> </TD>
<TD class=bg0>
<TABLE height=312 cellSpacing=0 cellPadding=0 width=718
border=0>
<TBODY>
<TR>
<form name="form1" method="post" action="envoimessage.php?id=<?php echo $membrefiche; ?>">
<TD class=txt1 height=273>
<TABLE cellSpacing=0 cellPadding=1 width="100%"
border=1>
<TBODY>
<TR>
<TH scope=row bgColor=#cccccc colSpan=6>
<P> </P>
<P>envoyer un message : </P>
<P> </P></TH></TR>
<TR>
<TD scope=row bgColor=#ffcc99 colSpan=6 height=36>
<DIV class=Style15 align=center>à : <?php echo $pseudo; ?></DIV></TD></TR>
<TR>
<TH height=201 colSpan=6 align="left" valign="top" scope=row>
<input name="id_envoyeur" type="hidden" value="<?php echo $visiteur; ?>" />
<input name="id_destinataire" type="hidden" value="<?php echo $membrefiche; ?>" />
<input name="dateenvoie" type="hidden" value="<?php echo date("Y-m-d"); ?>" />
<p>Titre :
<input name="titre" type="text" id="titre" size="100" maxlength="100">
</p>
<p>Message :<br>
<textarea name="message" cols="80" rows="10" id="message"></textarea>
</p>
<P class=Style14> </P>
<P class=Style14> </P></TH></TR></TBODY></TABLE>
<P align=center><INPUT type=submit value=Envoyer>
</P>
<P><A
href="mailto:[email protected]"></A></P></TD>
</form>
</TR>
<TR>
<TD class=txt1 bgColor=#cccccc height=39>
<P align="center" class=Style8><a href="fiche.php?id=<?php echo $visiteur; ?>">Retour à ma fiche </a></P></TD></TR></TBODY></TABLE></TD>
<TD background=""> </TD></TR>
<TR>
<TD height=15> </TD>
<TD> </TD>
<TD> </TD>
</TR></TBODY></TABLE>
<DIV align=center><A class=Style7
href="mailto:[email protected]">[email protected]</A></DIV></TD>
<TD class=bg1 width=8><IMG height=1
src="message envoyer_fichiers/clear.gif" width=8></TD>
<TD width=3><IMG height=1 src="message envoyer_fichiers/clear.gif"
width=3></TD></TR></TBODY></TABLE><!-- cellule pour votre contenu : fin --><!-- Début FOOTER --></TD></TR></TBODY></TABLE></CENTER><!-- fin FOOTER --></BODY></HTML>
[/php]if ( (isset($_POST['message'])) && (!empty($_POST['message'])){
$recherche = array(':oD', ':oP'); // détection des symboles
$remplace = array('<img src="smiley1.gif"/>', '<img src="smiley2.gif"/>'); // remplacement par des images
echo str_replace($recherche, $remplace, $_POST['message']);
exit();
}
ça te permettra de tester le remplacement de :oD par son imageif ( (isset($_POST['message'])) && (!empty($_POST['message'])) ){
$recherche = array(':oD', ':oP'); // détection des symboles
$remplace = array('<img src="smiley1.gif"/>', '<img src="smiley2.gif"/>'); // remplacement par des images
echo str_replace($recherche, $remplace, $_POST['message']);
exit();
} Utilisateurs parcourant ce forum : Bing [Bot] et 51 invités