Witam.
Znalazłem w pewnym forum kawałek kodu w JS który bardzo by mi się przydał dla mojej stronki.
kod wygląda tak :
//----------------------------------------------------
// Prosty tag ([tag]tekst[/tag])
//----------------------------------------------------
function simpletag(thetag) {
tag("[" + thetag + "]", "[/" + thetag + "]");
}
//----------------------------------------------------
// Taguje tekst
//----------------------------------------------------
function tag(bbopen, bbclose) {
var txtarea = document.form.text;
if ((clientVer >= 4) && is_ie && is_win) {
//Win IE
theSelection = document.selection.createRange().text;
if (!theSelection) {
txtarea.value += bbopen + bbclose;
txtarea.focus();
return;
}
document.selection.createRange().text = bbopen + theSelection + bbclose;
txtarea.focus();
return;
} else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0)) {
//Mozilla/gecko
mozTag(txtarea, bbopen, bbclose);
return;
} else {
//inna
txtarea.value += bbopen + bbclose;
txtarea.focus();
}
storeCaret(txtarea);
}
//----------------------------------------------------
// Taguje tekst pod mozilla
//----------------------------------------------------
function mozTag(txtarea, open, close) {
var selLength = txtarea.textLength;
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
if (selEnd == 1 || selEnd == 2) {
selEnd = selLength;
}
var s1 = (txtarea.value).substring(0,selStart);
var s2 = (txtarea.value).substring(selStart, selEnd);
var s3 = (txtarea.value).substring(selEnd, selLength);
txtarea.value = s1 + open + s2 + close + s3;
return;
}
funkcja ta zamienia tekst typu [ quote ] Coś [ / quote ]
Cytat
Jakiś tekst
i odpowiednio coś z nim robi według tego jak ustalimy.
Chciałem to napisać w PHP aby mi automatycznie zmieniało wiele rzeczy (coś jak na forum dodawanie kodu PHP czyli w znacznikach). Problem w tym że nie mam pojęcia jak to zrobić (IMG:
http://forum.php.pl/style_emoticons/default/sad.gif)
Wie ktoś z was jak to napisać lub gdzie jest przykład jakiś tego ?
Ten post edytował Setesh 12.05.2007, 10:41:06