Myślałem o 2 sposobach:
-w textarea (+ obliczenie liczby wierszy)
-w
Kod
KOD PHP
(zamiana na div),wyciągnięcie tekstu z pomiędzy tagów + htmlspecialchars
<form action="index.php?page=test" method="post"> <textarea name="tekst" style="width:400px;height:200px;"></textarea><input type="submit" name="wyslano"> </form> <?PHP { $tekst=$_POST["tekst"]; include('geshi/geshi.php'); $language = 'php'; $path = 'geshi/geshi'; $geshi = new GeSHi($tekst, $language, $path); } ?>
{ $tekst=$_POST["tekst"]; include('geshi/geshi.php'); $language = 'php'; $path = 'geshi/geshi'; $geshi = new GeSHi($tekst, $language, $path); $kolorowy = $geshi->parse_code(); }
<form action="index.php?page=test" method="post"> <textarea name="tekst" style="width:400px;height:200px;"></textarea><input type="submit" name="wyslano"> </form> <?PHP { $tekst=$_POST["tekst"]; include('geshi/geshi.php'); $language = 'php'; $path = 'geshi/geshi'; $geshi = new GeSHi($tekst, $language, $path); $kolorowy = $geshi->parse_code(); $kolorowy = preg_replace("#\[center\](.*?)\[/center\]#si",'<div style="text-align:center">\\1</div>',$kolorowy); $kolorowy = preg_replace("#\[right\](.*?)\[/right\]#si",'<div style="text-align:right">\\1</div>',$kolorowy); $kolorowy = preg_replace("#\[url=(http.*?)\](.*?)\[/url\]#si", "<A HREF=\"\\1\" TARGET=\"_blank\">\\2</A>", $kolorowy); $kolorowy = preg_replace("#\[color=(.*?)\](.*?)\[/color\]#si",'<font color="\\1">\\2</font>',$kolorowy); $kolorowy = preg_replace("#\[size=(.*?)\](.*?)\[/size\]#si",'<font size="\\1">\\2</font>',$kolorowy); } ?>
<?php "#\[b\](.*?)\[/b\]#si", "#\[code\](.*?)\[/code\]#si", "#\[i\](.*?)\[/i\]#si", /* i tak dalej */ ); "<b>\\1</b>", "div class=\"code\">\\1</div>", "<i>\\1</i>" /* i tak dalej */ ); ?>
$miesiac_pl = array(1 => 'stycznia', 'lutego', 'marca', 'kwietnia', 'maja', 'czerwca', 'lipca', 'sierpnia', 'września', 'października', 'listopada', 'grudnia'); $date = $dzien." ".$miesiac_pl[$miesiac]." ".$rok; //Tworzenie linku $link=$title; $polskie = array(',', ' - ',' ','ę', 'Ę', 'ó', 'Ó', 'Ą', 'ą', 'Ś', 's', 'ł', 'Ł', 'ż', 'Ż', 'Ź', 'ź', 'ć', 'Ć', 'ń', 'Ń','-',"'","/","?", '"', ":", 'ś', '!','.', '&', '&', '#', ';', '[',']','domena.pl', '(', ')', '`', '%', '”', '„', '…'); $miedzyn = array('-','-','-','e', 'e', 'o', 'o', 'a', 'a', 's', 's', 'l', 'l', 'z', 'z', 'z', 'z', 'c', 'c', 'n', 'n','-',"","","","","",'s','','', '', '', '', '', '', '', '', '', '', '', '', ''); // usuń wszytko co jest niedozwolonym znakiem // zredukuj liczbę myślników do jednego obok siebie // usuwamy możliwe myślniki na początku i końcu // na wszelki wypadek //Zapis do bazy $db->exec("INSERT INTO news VALUES(null, '$title', '$link', '$text', $cat, '$date')");
//Filtrowanie $ins = $db->prepare("INSERT INTO news VALUES(null, '$title', '$link', :text, $cat, '$date')"); $ins->bindValue(':text', $text, PDO::PARAM_STR); // właściwe wykonanie $ins->execute(); //Zapis do bazy
echo ' <div class="news"> <div class="news_header"> <div class="news_left"> <div class="news_title"> '.$w["title"].' </div> </div> <div class="news_right"> <img src="images/clock.png"/ style="padding-top:10px;"> '.$w["date"].' </div> </div> <div class="news_text">'; $tekst=$w["content"]; //Zamiana na encje include('bbcode.php'); echo '</div> <div class="news_bottom"> <a href="#">[Komentarze: 0]</a> </div> </div>';
.news_text{ font-family:verdana; padding:20px 10px 20px 10px; font-size:15px; }
<style type="text/css"> <?php ?> </style>
$geshi->set_overall_class('code'); $geshi->set_overall_id('kod');
'#(\[php\])(.*?)\[/php\]#si', '#(\[code\])(.*?)\[/code\]#si', '#(\[quote\])(.*?)\[/quote\]#si', '#(\[css\])(.*?)\[/css\]#si', '#(\[html\])(.*?)\[/html\]#si', '#(\[sql\])(.*?)\[/sql\]#si', '#(\[js\])(.*?)\[/js\]#si', ); function zamien($matches){ // $matches[0] zawiera kod ktory masz przepuscic przez geshi i ta funkcja ma zwrocic to co wypluwa geshi return to co wypluwa geshi z $matches[0] }
<form action="index.php?page=test" method="post"> <textarea name="tekst" style="width:400px;height:200px;"></textarea><input type="submit" name="wyslano"> </form> <?PHP { $art=($_POST["tekst"]); '#(\[php\])(.*?)\[/php\]#si', '#(\[code\])(.*?)\[/code\]#si', '#(\[quote\])(.*?)\[/quote\]#si', '#(\[css\])(.*?)\[/css\]#si', '#(\[html\])(.*?)\[/html\]#si', '#(\[sql\])(.*?)\[/sql\]#si', '#(\[js\])(.*?)\[/js\]#si', ); function zamien($matches){ include('geshi/geshi.php'); $language = 'php'; $path = 'geshi/geshi'; $geshi = new GeSHi($matches[0], $language, $path); $pokaz = $geshi->parse_code(); return $pokaz; } } ?>
<form action="index.php?page=test" method="post"> <textarea name="tekst" style="width:400px;height:200px;"></textarea><input type="submit" name="wyslano"> </form> <?PHP { $art=($_POST["tekst"]); '#(\[php\])(.*?)\[/php\]#si', '#(\[code\])(.*?)\[/code\]#si', '#(\[quote\])(.*?)\[/quote\]#si', '#(\[css\])(.*?)\[/css\]#si', '#(\[html\])(.*?)\[/html\]#si', '#(\[sql\])(.*?)\[/sql\]#si', '#(\[js\])(.*?)\[/js\]#si', ); } function zamien($matches){ include('geshi/geshi.php'); $language = 'php'; $path = 'geshi/geshi'; $geshi = new GeSHi($matches[0], $language, $path); $matches = $geshi->parse_code(); return $matches; } zamien($art); ?>
{ $art=($_POST["tekst"]); '#(\[php\])(.*?)\[/php\]#si', '#(\[code\])(.*?)\[/code\]#si', '#(\[quote\])(.*?)\[/quote\]#si', '#(\[css\])(.*?)\[/css\]#si', '#(\[html\])(.*?)\[/html\]#si', '#(\[sql\])(.*?)\[/sql\]#si', '#(\[js\])(.*?)\[/js\]#si', ); } function zamien($matches){ include('geshi/geshi.php'); $language = 'php'; $path = 'geshi/geshi'; $geshi = new GeSHi($matches[0], $language, $path); $kod = $geshi->parse_code(); return $kod; }
<?PHP { $art=($_POST["tekst"]); '#(\[php\])(.*?)\[/php\]#si', '#(\[code\])(.*?)\[/code\]#si', '#(\[quote\])(.*?)\[/quote\]#si', '#(\[css\])(.*?)\[/css\]#si', '#(\[html\])(.*?)\[/html\]#si', '#(\[sql\])(.*?)\[/sql\]#si', '#(\[js\])(.*?)\[/js\]#si', ); } function zamien($matches){ include('geshi/geshi.php'); $language = 'php'; $path = 'geshi/geshi'; $geshi = new GeSHi($matches[0], $language, $path); $kod = $geshi->parse_code(); return $kod; } ?>
<?PHP { $art=($_POST["tekst"]); '#(\[php\])(.*?)\[/php\]#si', '#(\[code\])(.*?)\[/code\]#si', '#(\[quote\])(.*?)\[/quote\]#si', '#(\[css\])(.*?)\[/css\]#si', '#(\[html\])(.*?)\[/html\]#si', '#(\[sql\])(.*?)\[/sql\]#si', '#(\[js\])(.*?)\[/js\]#si', ); } function zamien($matches){ include_once('geshi/geshi.php'); $language = 'php'; $path = 'geshi/geshi'; $geshi = new GeSHi($matches[0], $language, $path); $kod = $geshi->parse_code(); return $kod; } ?>
<?PHP { $art=($_POST["tekst"]); } function zamien($matches){ include_once('geshi/geshi.php'); $language = 'php'; $path = 'geshi/geshi'; $geshi = new GeSHi($matches[2], $language, $path); $kod = $geshi->parse_code(); return '<div class="code">'.$kod.'</div>'; } ?>
<?PHP //bbcode function zamien($matches){ include_once('geshi/geshi.php'); $language = 'php'; $path = 'geshi/geshi'; $geshi = new GeSHi($matches[2], $language, $path); $kod = $geshi->parse_code(); return '<div class="code">'.$kod.'</div>'; } ?>
//bbcode function zamien($matches){ include_once('geshi/geshi.php'); $language = 'php'; $path = 'geshi/geshi'; $geshi = new GeSHi($matches[2], $language, $path); $kod = $geshi->parse_code(); return '<div class="code">'.$kod.'</div>'; }
//bbcode function zamien($matches){ include_once('geshi/geshi.php'); $language = 'php'; $path = 'geshi/geshi'; $geshi = new GeSHi($matches[2], $language, $path); $kod = $geshi->parse_code(); return '<div class="code">'.$kod.'</div>'; }