1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| <?php
if (isset($_POST['message'])){
$texte=$_POST['message'];
$texte = preg_replace('#\[g\](.+)\[/g\]#isU', '<strong>$1</strong>', $texte);
$texte = preg_replace('#\[i\](.+)\[/i\]#isU', '<em>$1</em>', $texte);
$texte = preg_replace('#\[s\](.+)\[/s\]#isU', '<u>$1</u>', $texte);
$texte = preg_replace('#\[u=(.+)\](.+)\[/u\]#isU', '<a href="$1">$2</a>', $texte);
echo $texte;
}
?>
<html>
<head>
<title>Ajouter du texte au milieu d'un textarea</title>
<script language="JavaScript" type="text/javascript">
function lien2(){
var m = prompt("entrez lien","http://");
if (m!=null && m!="http://")
AddText('[u='+m+']','','[/u]')
}
function AddText(startTag,defaultText,endTag)
{
with(document.poster)
{
if (message.createTextRange)
{
var text;
message.focus(message.caretPos);
message.caretPos = document.selection.createRange().duplicate();
if(message.caretPos.text.length>0)
{
var sel = message.caretPos.text;
var fin = '';
while(sel.substring(sel.length-1, sel.length)==' ')
{
sel = sel.substring(0, sel.length-1)
fin += ' ';
}
message.caretPos.text = startTag + sel + endTag + fin;
}
else
message.caretPos.text = startTag+defaultText+endTag;
}
else message.value += startTag+defaultText+endTag;
}
}
</script>
</head>
<body>
<form name="poster" action="" method="POST">
<table border="1"cellpadding=0 cellspacing=0>
<tr>
<td><a href="#" onclick="AddText('[g]','','[/g]');">Gras</a></td>
<td><a href="#" onclick="AddText('','','');">Italique</a></td>
<td><a href="#" onclick="AddText('','','');">Souligné</a></td>
<td><a href="#" onclick="lien2()">Url</a></td>
</tr>
<tr>
<td colspan="4">
<textarea rows="10"cols="60" name="message">
Principium autem unde latius se funditabat, emersit ex negotio tali. Chilo ex vicario et coniux eius Maxima nomine, questi apud Olybrium ea .
</textarea>
</td>
</tr>
</table>
<br>
<input type="submit" value="envoyer">
</form>
</body>
</html> |
Partager