Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: bbcode
Forum PHP.pl > Forum > PHP
modern
Nie wiem dlaczego ale moja funkcja bbcode zatrzymuje cała reszte skryptu... sad.gif
a sam bbcode dziala poprawnie bo wszystko ladnie zamienia
  1. <?
  2.  
  3. // bbcode
  4. Function bbcode($text){
  5.  
  6. // usun zbedne
  7. $text=htmlspecialchars(trim($text));
  8.  
  9. // Kolorowanie składni
  10. $text=preg_replace_callback("#[php](.*?)[/php]#si", "bbcode_phpCode", $text);
  11.  
  12. // Odnośnik e-mail(własne definiowanie wyświetlanego tekstu)
  13. $text = preg_replace("#[email=([a-z0-9-_.]+?)@([w-]+.([w-.]+.)?[w]+)?(.*?)](.*?)[/email]#i", "<a href="mailto:1@2">5</a>", $text);
  14.  
  15. // Odnośnik, otwieranie w nowym oknie
  16. $text = preg_replace("#(.*?)?(.*?)#si", "<A HREF="12" TARGET="_blank">12</A>", $text);
  17.  
  18. // Odnośnik, otwieranie w nowym oknie, definiowanie treści odnośnika
  19. $text = preg_replace("#(.*?)#si", "<A HREF="http://2" TARGET="_blank">3</A>", $text);
  20.  
  21. // Odnośnik, otwieranie w tym samym oknie
  22. $text = preg_replace("#[url2](.*?)?(.*?)[/url2]#si", "<A HREF="12">12</A>", $text);
  23.  
  24. // Odnośnik, otwieranie w tym samym oknie, definiowanie treści odnośnika
  25. $text = preg_replace("#(.*?)#si", "<A HREF="2">3</A>", $text);
  26.  
  27. // Automatyczne tworzenie linków
  28. $text = preg_replace_callback("#([n ])([a-z]+?)://([a-z0-9-.,?!%*_#:;~&$@/=+]+)#si", "bbcode_autolink", $text);
  29. $text = preg_replace("#([n ])www.([a-z0-9-]+).([a-z0-9-.~]+)((?:/[a-z0-9-.,?!%*_#:;~&$@/=+]*)?)#i", " <a href="http://www.2.34" target="_blank">www.2.34</a>", $text);
  30. $text = preg_replace("#([n ])([a-z0-9-_.]+?)@([w-]+.([w-.]+.)?[w]+)#i", "1<a href="java script:mailto:mail('2','3');">2_(at)_3</a>", $text);
  31.  
  32. // Ukrywanie treści
  33. $text = preg_replace_callback("#[ukryj="?(.*?)"?](.*?)[/ukryj]#si", 'ukryj', $text);
  34.  
  35. // Pogrubiony tekst
  36. $text = preg_replace("#(.*?)#si", "<b>1</b>", $text);
  37.  
  38. // Pochylony tekst
  39. $text = preg_replace("#(.*?)#si", "<i>1</i>", $text);
  40.  
  41. // Podkreślony tekst
  42. $text = preg_replace("#(.*?)#si", "<u>1</u>", $text);
  43.  
  44. // Pomniejszanie tekstu
  45. $text = preg_replace("#[sm](.*?)[/sm]#si", "<small>1</small>", $text);
  46.  
  47. // Powiększanie tekstu
  48. $text = preg_replace("#[big](.*?)[/big]#si", "<big>1</big>", $text);
  49.  
  50. // Akapit
  51. $text = preg_replace("/[p](.*?)[/p]/si", "<p>1</p>", $text);
  52.  
  53. // Akapit z wyrównaniem
  54. $text = preg_replace("#[p=(http://)?(.*?)](.*?)[/p]#si", "<p align="2">3</p>", $text);
  55.  
  56. // Wyśrodkowanie tekstu
  57. $text = preg_replace("/
    (.*?)
    /si"
    , "<center>1</center>", $text);
  58.  
  59. // Kolor tekstu
  60. $text = preg_replace("#(.*?)#si", "<span style="color:2">3</span>", $text);
  61.  
  62. // Wielkość czcionki
  63. $text = preg_replace("#(.*?)#si", "<span style="font-size:2">3</span>", $text);
  64.  
  65. // Obrazek
  66. $text = preg_replace("#[img](.*?)[/img]#si", "<img src="1" border="0" alt="Obrazek" />", $text);
  67.  
  68. // Obrazek z katalogu img
  69. $text = preg_replace("#[ftp_img](.*?)[/ftp_img]#si", "<img src="img/1" border="0" alt="Obrazek" />", $text);
  70.  
  71. // Obrazek Lewo
  72. $text = preg_replace("#[img:left](.*?)[/img]#si", "<img align="left" src="1" border="0" alt="Obrazek" />", $text);
  73.  
  74. // Obrazek z katalogu img Lewo
  75. $text = preg_replace("#[ftp_img:left](.*?)[/ftp_img]#si", "<img align="left" src="img/1" border="0" alt="Obrazek" />", $text);
  76.  
  77. // Obrazek Prawo
  78. $text = preg_replace("#[img:right](.*?)[/img]#si", "<img align="right" src="1" border="0" alt="Obrazek" />", $text);
  79.  
  80. // Obrazek z katalogu img Prawo
  81. $text = preg_replace("#[ftp_img:right](.*?)[/ftp_img]#si", "<img align="right" src="img/1" border="0" alt="Obrazek" />", $text);
  82.  
  83. // Obrazek Center
  84. $text = preg_replace("#[img:center](.*?)[/img]#si", "<img align="center" src="1" border="0" alt="Obrazek" />", $text);
  85.  
  86. // Obrazek z katalogu img Center
  87. $text = preg_replace("#[ftp_img:center](.*?)[/ftp_img]#si", "<img align="center" src="img/1" border="0" alt="Obrazek" />", $text);
  88.  
  89. // Pozioma linia
  90. $text = preg_replace("#[hr=(d{1,2}|100)]#si", "<hr class="linia" width="1%">", $text);
  91.  
  92. // Spacja
  93. $text=str_replace('[spacja]',' ',$text);
  94.  
  95. // Znaki specjalne
  96. // znaki specjalne
  97. $text = str_replace('&plusmn;', 'ą', $text);
  98. $text = str_replace('&trade;', '™', $text);
  99. $text = str_replace('&bull;', '•', $text);
  100. $text = str_replace('&deg;', '°', $text);
  101. $text = str_replace('&copy;', 'Š', $text);
  102. $text = str_replace('&reg;', 'Ž', $text);
  103. $text = str_replace('&hellip;', '…', $text);
  104.  
  105. // błędne kodowanie m.in. z phpmyadmina
  106. $text = str_replace('ą', 'ą', $text);
  107. $text = str_replace('ć', 'ć', $text);
  108. $text = str_replace('ę', 'ę', $text);
  109. $text = str_replace('ł', 'ł', $text);
  110. $text = str_replace('ś', 'ś', $text);
  111. $text = str_replace('ź', 'Ľ', $text);
  112. $text = str_replace('ż', 'ż', $text);
  113.  
  114. // znaki specjalne z m$ word
  115. $text = str_replace('ą', 'ą', $text);
  116. $text = str_replace('’', ''', $text);
  117. $text = str_replace('&#8222;', '"', $text);
  118. $text = str_replace('”', '"', $text);
  119. $text = str_replace('“', '"', $text);
  120. $text = str_replace('–', '-', $text);
  121. $text = str_replace('…', '…', $text);
  122.  
  123. // Wykonaj html
  124. $text=preg_replace_callback("#
    1. (.*?)
    #si"
    , "html_entity_decode", $text);
  125.  
  126. // Kod
  127. $text = preg_replace("#[code](.*?)[/code]#si", "<pre class="kod">1</pre>", $text);
  128.  
  129. // Kod, podany autor
  130. $text = preg_replace("#[code=(http://)?(.*?)](.*?)[/code]#si", "<pre class="kod">3</pre>", $text);
  131.  
  132. // Cytat
  133. $text = preg_replace("#<!--quoteo--><div class='quotetop'>CYTAT</div><div class='quotemain'><!--quotec-->(.*?)<!--QuoteEnd--></div><!--QuoteEEnd-->#si", "<p class="cytat">1</p>", $text);
  134.  
  135. // Cytat, podany autor
  136. $text = preg_replace("#<!--QuoteBegin-(http://)?(.*?)+--><div class='quotetop'>CYTAT((http://)?(.*?))</div><div class='quotemain'><!--QuoteEBegin-->(.*?)<!--QuoteEnd--></div><!--QuoteEEnd-->#si", "<p class="cytat">2: 3</p>", $text);
  137.  
  138. // Lista
  139.  
  140. $text = preg_replace("#
      (.*?)
    #si"
    , "<ul>1</ul>", $text);
  141. $text = preg_replace("#[list=(http://)?(.*?)](.*?)[/list]#si", "<ol type="2">3</ol>", $text);
  142. $text = preg_replace("#[*](.*?)s#si", "<li>1</li>", $text);
  143.  
  144. // Odnośnik e-mail
  145. $text = preg_replace("#([a-z0-9-_.]+?)@([w-]+.([w-.]+.)?[w]+)#i", "<a href="mailto:1@2">1@2</a>", $text);
  146.  
  147. // kolejny wiersz
  148. $text=nl2br($text);
  149.  
  150. // kodowanie kodu
  151. $text = preg_replace_callback("#<base64>(.*?)</base64>#si", "base64decode", $text);
  152.  
  153. // js
  154. $text = preg_replace_callback("#<(.*?)javascript(.*?)>#si", "bbcode_js", $text);
  155.  
  156. // wynik
  157. return $text;}
  158.  
  159.  
  160. ?>
legorek
Co to znaczy zarymuej skrypt ? Są jakies błedy ? Jak wywołujesz tą funkcję ?
Denver
Abstrachując od samego bbcode'u: Przy tylu operacjach na tekście warto by chyba w deklaracji funkcji zastosować referencję
Kod
function bbcode (& $text) { .... }
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.