I början av Januari 2014 låstes Whoa och du kan alltså ej logga in eller skriva något nytt i forumen. Innehåll i forum osv kommer finnas tillgängligt. Läs Mer »

Göra text bold, till länkar osv...

Hobby & Fritid - Datorer & Teknik

   
Producent

2006-12-16 21:32

Göra text bold, till länkar osv...

Jag har en nyhetsgrejj, vill gärna slänga in en funktion som man kan göra länkar om man markerar texten, eller tjock eller italic...

Var kan man hitta sådant

Since 1984
@realgizlee // twitter
Producent

2006-12-16 21:35
Så som de va här på whoa innan, man kan även skriva (b)BOLD(/b)
Since 1984
@realgizlee // twitter

2006-12-16 21:59
replace("(b)", "<font face="bold">")

;C
cry me a river!
--> thcrew

2006-12-16 21:59
fast replace får du ju byta ut mot lämplig funktion, men det e väl det enklaste =)
cry me a river!
--> thcrew
Producent

2006-12-16 22:02
alltså, det är php sidan är i, så, men kan du förklara mer utförligt ?
Since 1984
@realgizlee // twitter

2006-12-16 22:15
jamen, när texten postas så går den genom ett script som letar igenom texten efter en viss sträng och byter ut den mot en annan,

tex "(B)" -> <font face="bold"> text fram tills (/B).... "(/B)" -> </font> osv..

borde väl gå fint?
cry me a river!
--> thcrew

2006-12-16 22:17
hmm <b> räcker väl antar jag iofs..
cry me a river!
--> thcrew
Producent

2006-12-16 22:30
skriv hela scriptet som det skall vara så får ja se

e de typ

<javascript>
replace("(b)", "<b>")
replace("(/b)", "</b>")
</script>
Since 1984
@realgizlee // twitter
Producent

2006-12-16 22:33
eller e de ?

<?
replace("(b)", "<b>")
replace("(/b)", "</b>")
?>

Since 1984
@realgizlee // twitter

2006-12-16 22:52
ingen aning, du får la göra nått själv =)
cry me a river!
--> thcrew

2006-12-16 22:53

<html>
<body>

<script type="text/javascript">

var txt="Hello World!"

document.write("<p>Big: " + txt.big() + "</p>")
document.write("<p>Small: " + txt.small() + "</p>")

document.write("<p>Bold: " + txt.bold() + "</p>")
document.write("<p>Italic: " + txt.italics() + "</p>")

document.write("<p>Blink: " + txt.blink() + " (does not work in IE)</p>")
document.write("<p>Fixed: " + txt.fixed() + "</p>")
document.write("<p>Strike: " + txt.strike() + "</p>")

document.write("<p>Fontcolor: " + txt.fontcolor("Red") + "</p>")
document.write("<p>Fontsize: " + txt.fontsize(16) + "</p>")

document.write("<p>Lowercase: " + txt.toLowerCase() + "</p>")
document.write("<p>Uppercase: " + txt.toUpperCase() + "</p>")

document.write("<p>Subscript: " + txt.sub() + "</p>")
document.write("<p>Superscript: " + txt.sup() + "</p>")

document.write("<p>Link: " + txt.link("http://www.w3schools.com") + "</p>")
</script>

</body>
</html>


cry me a river!
--> thcrew

2006-12-16 22:54
there u go
cry me a river!
--> thcrew
Producent

2006-12-16 23:43
hittade en bättre på phpportalens hemsida, men thanx anyway main
Since 1984
@realgizlee // twitter

2006-12-16 23:48
nemas..
cry me a river!
--> thcrew
Producent

2006-12-17 00:09
delar med mig då

Det är ett Nyhetsscript i PHP
Du måste lägga in lösenord på 3 ställen, det är dem som är märkta i bold.
Du måste också skapa en txt fil som ligger i samma mapp som skall heta news.txt


<?
if($action == "edit" && isset($HTTP_POST_VARS)) {
    //obviously you should change this password on the next line
    if($HTTP_POST_VARS == "SKRIV IN LÖSENORD HÄR") {
        //First let's recompile that line with the pipe symbols so we can reinsert it
        $line = $HTTP_POST_VARS . "|" . $HTTP_POST_VARS;
        $line .= "|" . $HTTP_POST_VARS;
        $line = str_replace("\r\n","<BR>",$line);
        $line .= "\r\n";
        $data = file('news.txt');
        $data = $line;
        //the next line makes sure the $data array starts at the beginning
        reset($data);
        //now we open the file with mode 'w' which truncates the file
        $fp = fopen('news.txt','w');
        foreach($data as $element) {
            fwrite($fp, $element);
        }
        fclose($fp);
        echo "Nyhet ändrat<BR><BR>\n";
        echo "<a href=\"$PHP_SELF\">Tillbaka</a>\n";
        exit;
    } else {
        echo "Fel lösenord\n";
        exit;
    }
}
if($action == "edit") {
    $data = file('news.txt');
    $element = trim($data);
    $pieces = explode("|", $element);
    //the next line is to reverse the process of turning the end of lines into breaking returns
    $news = str_replace("<BR>","\r\n",$pieces);
    echo "Gör dem ändringar du vill göra och tryck på spara<BR>\n";
    echo "<FORM ACTION=\"$PHP_SELF?action=edit\" METHOD=\"POST\" NAME=\"editform\">\n";
    echo "Name:<BR>\n";
    echo "<INPUT TYPE=\"text\" SIZE=\"30\" NAME=\"name\" value=\"".$pieces."\"><BR>\n";
    echo "The News:<BR>\n";
    echo "<TEXTAREA NAME=\"news\" COLS=\"40\" ROWS=\"5\">".$news."</TEXTAREA><BR><BR>\n";
    echo "Password:<BR>\n";
    echo "<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>\n";
    echo "<INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"".$pieces."\">\n";
    echo "<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";
    echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Save\"><BR>\n";
    echo "</FORM>\n";
    exit;
}
if($action == "delete" && isset($HTTP_POST_VARS)) {
Since 1984
@realgizlee // twitter
Producent

2006-12-17 00:10
    //obviously you should change this password on the next line
    if($HTTP_POST_VARS == "SKRIV LÖSENORD HÄR OCKSÅ") {
        $data = file('news.txt');
        //this next line will remove the single news item from the array
        array_splice($data,$id,1);
        //now we open the file with mode 'w' which truncates the file
        $fp = fopen('news.txt','w');
        foreach($data as $element) {
            fwrite($fp, $element);
        }
        fclose($fp);   
        echo "Nyhet borttagen!<BR><BR>\n";   
        echo "<a href=\"$PHP_SELF\">Tillbaka</a>\n";
        exit;
    } else {
        echo "Fel lösenord!\n";
        exit;
    }
}
if($action == "delete") {
    echo "<H2>Du kommer nu att ta bort nyheten!</H2>\n";
    $data = file('news.txt');
    $element = trim($data);
    $pieces = explode("|", $element);
    echo $pieces . "<BR>" . "<b>// " . $pieces . " on " . $pieces . "</b>\n";
    echo "<BR><BR>\n";
    echo "Är du säker på att ta bort nyheten? Skriv annars i lösenordet och tryck enter<BR>\n";
    echo "<FORM ACTION=\"$PHP_SELF?action=delete\" METHOD=\"POST\" NAME=\"deleteform\">\n";
    echo "Lösenord:<BR>\n";
    echo "<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>\n";
    echo "<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";
    echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Delete\"><BR>\n";
    echo "</FORM>\n";
    exit;
}


echo "<H1><u>Nuvarande nyheter</u></H1>\n";
$data = file('news.txt');
//next line removed to make everything else easier in the admin script
//$data = array_reverse($data);
foreach($data as $key=>$element) {
    $element = trim($element);
    $pieces = explode("|", $element);
    echo $pieces . "<BR>" . "<b>// " . $pieces . " on " . $pieces . "</b>\n";
    echo "&nbsp;<a href=\"$PHP_SELF?action=delete&id=$key\">Delete</a>\n";
    echo "&nbsp;<a href=\"$PHP_SELF?action=edit&id=$key\">Edit</a>\n";
    echo "<BR><BR>\n";
}
echo "<HR>\n";
echo "<H1><u>Lägg till nyheter</u></H1>\n";
if($HTTP_POST_VARS) {
    if($HTTP_POST_VARS == 'SKRIV IN LÖSENORD HÄR MED') {
        if(!$HTTP_POST_VARS) {
            echo "You must enter a name";
            exit;

Since 1984
@realgizlee // twitter
Producent

2006-12-17 00:11
        }
        if(!$HTTP_POST_VARS['news']) {
            echo "You must enter some news";
            exit;
        }
        if(strstr($HTTP_POST_VARS['name'],"|")) {
            echo "Name cannot contain the pipe symbol - |";
            exit;
        }
        if(strstr($HTTP_POST_VARS['news'],"|")) {
            echo "News cannot contain the pipe symbol - |";
            exit;
        }
        $fp = fopen('news.txt','a');
        if(!$fp) {
            echo "Error opening file!";
            exit;
        }
        $line = date("y.m.d") . "|" . $HTTP_POST_VARS['name'];
        $line .= "|" . $HTTP_POST_VARS['news'];
        $line = str_replace("\r\n","<BR>",$line);
        $line .= "\r\n";
        fwrite($fp, $line);
        if(!fclose($fp)) {
            echo "Error closing file!";
            exit;
        }
        echo "<b>Nyhet tillagd!</b>\n";   
    } else {
        echo "Fel lösenord";
    }
}

?>
<html>
<head>
<title>L&Auml;GG TILL NYHETER !</title>
</head>
<body onLoad="info.innerHTML = description[3]; return true">
 
<script language="JavaScript" type="text/javascript">
 
/* Funktion som lägger till olika taggar */
function tag(f, i, t){
    if (t=='lnk')
         f.elements[i].value += "<a href=LÄNKEN HÄR> LÄNKTEXT </a>";
    if (t=='fet')
          f.elements[i].value += "<b></b>";
    if (t=='kursiv')
          f.elements[i].value += "<i></i>";
}
 /* Förklaringar till taggarna */
var description = new Array();
description[0] = "Lägg till en länk";
description[1] = "Lägg till fet text";
description[2] = "Lägg till kursiv text";
description[3] = "<-- Klicka för att lägga till taggar";
 
</script>
<title>L&Auml;GG TILL NYHETER !</title>
<FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry">
Ditt namn:<BR>
<INPUT TYPE="text" SIZE="30" NAME="name"><BR>
Nyheten:<BR>
<TEXTAREA NAME="news" COLS="40" ROWS="5"></TEXTAREA><BR>
<input
type="button" value="&laquo; url" onMouseOver="info.innerHTML =
description[0]; return true" onMouseOut="info.innerHTML=description[3];
return true" onClick="tag(this.form, 'news', 'lnk')" />
<input
type="button" value="&laquo; b" onMouseOver="info.innerHTML =
description[1]; return true" onMouseOut="info.innerHTML=description[3];
return true" onClick="tag(this.form, 'news', 'fet')" />
<input
type="button" value="&laquo; i" onMouseOver="info.innerHTML =
description[2]; return true" onMouseOut="info.innerHTML=description[3];
return true" onClick="tag(this.form, 'news', 'kursiv')" />
<span id="info"></span>
<BR>
<BR>
Lösenord:<BR>
<INPUT TYPE="password" SIZE="30" NAME="password"><BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Spara"><BR>
</FORM>
</body>
</html>
Since 1984
@realgizlee // twitter