URLs im Text markieren

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • hmm also habe jetzt folgendes probiert:

    in meiner function makeclickable

    Quellcode

    1. $ret = preg_replace("#\[php\](.*?)\[/php\]#se","'<b>'.php_syntax('\\1').'</b>'",$ret);


    und die function php_syntax die ursprünglich von www.php.net ist:

    Quellcode

    1. function php_syntax($code, $high_light = 1, $lines_number = 1)
    2. {
    3. if (!is_array($code)) $code = explode("\n", $code);
    4. $count_lines = count($code);
    5. foreach ($code as $line => $code_line) {
    6. if ($lines_number) $r1 = "<span class=\"lines_number\">".($line + 1)." </span>";
    7. if ($high_light) {
    8. if (ereg("<\?(php)?[^[:graph:]]", $code_line)) {
    9. $r2 = highlight_string($code_line, 1);
    10. } else {
    11. $r2 = ereg_replace("(&lt;\?php&nbsp;)+", "", highlight_string("<?php ".$code_line, 1));
    12. }
    13. } else {
    14. $r2 = (!$line) ? "<pre>" : "";
    15. $r2 .= htmlentities($code_line);
    16. $r2 .= ($line == ($count_lines - 1)) ? "</pre>" : "";
    17. }
    18. $r .= $r1.$r2;
    19. }
    20. return($r);
    21. }
    Alles anzeigen



    so wenn ich jetz in meine "msg" Textarea folgendes eingebe:

    "Eingabe" schrieb:

    PHP-Quellcode

    1. <?php
    2. print "hello wORLD";
    3. if (($lala)=="huhu") { $dothis=$das; };
    4. ?>


    erhalte ich folgendes:

    "Ausgabe" schrieb:

    1
    <?php


    2
    print "Hello World\\";


    3
    if (($lala)=="huhu\\") { $dothis=$das; };


    4
    ?>


    natürlich im highlight aber irgendwie macht er mir riesen <br>´s rein in jede zeile -.-
    und baut mit diese \\ rein
    Beste Grüße,
    M4rc3L-XCN
  • Ich gebe die datei mal frei für andere damit
    Sie sich das anschauen können wie das nu am ende funzt ^^

    Quellcode

    1. <?php
    2. function php_syntax($code)
    3. {
    4. $high_light = 1;
    5. $lines_number = 0;
    6. if (!is_array($code)) $code = explode("\n", $code);
    7. $count_lines = count($code);
    8. foreach ($code as $line => $code_line) {
    9. if ($lines_number) $r1 = "<b>".($line + 1).": </b>";
    10. if ($high_light) {
    11. if (ereg("<\?(php)?[^[:graph:]]", $code_line)) {
    12. $r2 = highlight_string($code_line, 1);
    13. } else {
    14. $r2 = ereg_replace("(&lt;\?php&nbsp;)+", "", highlight_string("<?php ".$code_line, 1));
    15. }
    16. } else {
    17. $r2 = (!$line) ? "<pre>" : "";
    18. $r2 .= htmlentities($code_line);
    19. $r2 .= ($line == ($count_lines - 1)) ? "</pre>" : "";
    20. }
    21. $r .= $r1.$r2;
    22. $r = str_replace("\\","",$r);
    23. $r = str_replace("<br>","",$r);
    24. $r = str_replace("\n","",$r);
    25. }
    26. return($r);
    27. }
    28. function phpline_syntax($code)
    29. {
    30. $high_light = 1;
    31. $lines_number = 1;
    32. if (!is_array($code)) $code = explode("\n", $code);
    33. $count_lines = count($code);
    34. foreach ($code as $line => $code_line) {
    35. if ($lines_number) $r1 = "<b>".($line + 1).": </b>";
    36. if ($high_light) {
    37. if (ereg("<\?(php)?[^[:graph:]]", $code_line)) {
    38. $r2 = highlight_string($code_line, 1);
    39. } else {
    40. $r2 = ereg_replace("(&lt;\?php&nbsp;)+", "", highlight_string("<?php ".$code_line, 1));
    41. }
    42. } else {
    43. $r2 = (!$line) ? "<pre>" : "";
    44. $r2 .= htmlentities($code_line);
    45. $r2 .= ($line == ($count_lines - 1)) ? "</pre>" : "";
    46. }
    47. $r .= $r1.$r2;
    48. $r = str_replace("\\","",$r);
    49. $r = str_replace("<br>","",$r);
    50. $r = str_replace("\n","",$r);
    51. }
    52. return($r);
    53. }
    54. function make_clickable($text)
    55. {
    56. $ret = $text;
    57. // matcht protokolle http:// oder ftp:// oder skype://
    58. $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
    59. // matcht urls die mit www oder ftp beginnen
    60. $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
    61. // matcht email adressen
    62. $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
    63. // URL bb
    64. $ret = preg_replace("#\[url=([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#si","<a href=\"\\1\" target=\"_blank\">\\2</a>", $ret);
    65. // Color funktion
    66. $ret = preg_replace("#\[color=(.*?)\](.*?)\[/color\]#si","<span style=\"color:#\\1\">\\2</span>", $ret);
    67. // fett schrift
    68. $ret = preg_replace("#\[b\](.*?)\[/b\]#si", "<b>\\1</b>", $ret);
    69. // underline schrift
    70. $ret = preg_replace("#\[u\](.*?)\[/u\]#si", "<u>\\1</u>", $ret);
    71. // kursiv schrift
    72. $ret = preg_replace("#\[i\](.*?)\[/i\]#si", "<em>\\1</em>", $ret);
    73. // aufzählung erstellen
    74. $ret = preg_replace("#\[list\](.*?)\[/list\]#si", "<li>\\1</li>", $ret);
    75. // Bilder einfügen
    76. $ret = preg_replace("#\[img\](.*?)\[/img\]#si", "<img src=\"\\1\"></img>", $ret);
    77. // php code ???
    78. $ret = preg_replace("#\[code=php\](.*?)\[/code\]#se","php_syntax('\\1')",$ret);
    79. $ret = preg_replace("#\[code=phpline\](.*?)\[/code\]#se","phpline_syntax('\\1')",$ret);
    80. return($ret);
    81. }
    82. if (!empty($_POST['msg']))
    83. {
    84. $ausgabe=nl2br(make_clickable($_POST['msg']));
    85. print '<table width="539" border="1" cellpadding="1" cellspacing="1" bordercolor="#0000CC" bgcolor="#CCCCCC"><tr><td>'.$ausgabe.'</td></tr></table>';
    86. }
    87. $resend = $_POST['msg'];
    88. $resend = str_replace("\\","",$resend);
    89. $resend = str_replace("<br>","",$resend);
    90. $resend = str_replace("\n","",$resend);
    91. ?>
    92. <br />
    93. <br />
    94. <br />
    95. <br />
    96. <em><strong>Verwendbare BB-Codes:</strong></em>
    97. <table width="539" border="0">
    98. <tr>
    99. <td width="246">&nbsp;</td>
    100. <td width="283">&nbsp;</td>
    101. </tr>
    102. <tr>
    103. <td><strong>LINKS</strong></td>
    104. <td>[url=http://domain.tld]Beschreibung[/url]</td>
    105. </tr>
    106. <tr>
    107. <td><strong>FETT-SCHRIFT</strong></td>
    108. <td> [b]Text[/b]</td>
    109. </tr>
    110. <tr>
    111. <td><strong>KURSIV-SCHRIFT</strong></td>
    112. <td>[i]Text[/i]</td>
    113. </tr>
    114. <tr>
    115. <td><strong>UNTERSTRICHENE-SCHRIFT</strong></td>
    116. <td>[u]Text[/u]</td>
    117. </tr>
    118. <tr>
    119. <td><strong>FARBIGE-SCHRIFT</strong></td>
    120. <td>[color=000000]Text[/color]</td>
    121. </tr>
    122. <tr>
    123. <td><strong>AUFZ&Auml;HLUNG</strong></td>
    124. <td>[list]Text[/list]</td>
    125. </tr>
    126. <tr>
    127. <td><strong>BILD</strong></td>
    128. <td>[img]http://domain.tld/pic.jpg[/img]</td>
    129. </tr>
    130. <tr>
    131. <td><strong>PHP-CODE (ohne Zeilennummern)</strong></td>
    132. <td>[code=php]Code[/code]</td>
    133. </tr>
    134. <tr>
    135. <td><strong>PHP-CODE (mit Zeilennummern)</strong> </td>
    136. <td>[code=phpline]Code[/code]</td>
    137. </tr>
    138. </table>
    139. <form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post">
    140. <label>
    141. <textarea name="msg" id="msg" cols="80" rows="15"><?php print $resend; ?></textarea>
    142. </label>
    143. <br>
    144. <label>
    145. <input type="submit" name="submit" id="submit" value=" Anschauen">
    146. </label>
    147. </form>
    Alles anzeigen


    //EDIT by d0nut
    //hab den dateiinhalt vom zip-archiv direkt ins posting kopiert und dabei einrückungen optimiert
    //EDIT by marcel
    // wenn du das so meinst dann machen wir das halt so ^^
    // habe noch "Aufzählung" und die "Color" funktion hinzugefügt
    Beste Grüße,
    M4rc3L-XCN
  • //EDIT by BendIt

    bitte keine doppel/mehrfachpsts (dafür gibts den edit/bearbeiten button ;)

    http://selfphp.de bzw http://de.selfhtml.org und google.de sind coders freunde

    HTML Tags sollte er annehmen wenn du die zeichenkette richtig escapest

    ansonsten mit strip_tags() arbeiten und dabei die erlaubten tags mit übergeben

    mfg da BendIt
    .:Reden Ist Schweigen und Silber Ist Gold:.

    real programmers don't comment their code: if it was hard to write, it should be hard to read!