Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> BBCode, działający skrypt
Fipaj
post
Post #1





Grupa: Zarejestrowani
Postów: 691
Pomógł: 0
Dołączył: 19.01.2005
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Oto ciekawy skrypt obsługi BBCode... Jest bardzo prosty, przez co łatwo dodawać nowe funkcje. Proszę o krytykę i pomysły na nowe funkcje (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

  1. <?php
  2.  
  3. function bbcode ($ciag) {
  4.     // [kursywa]
  5.     $ciag = str_replace ('[kursywa]', '<i>', $ciag);
  6.     $ciag = str_replace ('[/kursywa]', '</i>', $ciag);
  7.  
  8.     // [podkreslenie]
  9.     $ciag = str_replace ('[podkreslenie]', '<u>', $ciag);
  10.     $ciag = str_replace ('[/podkreslenie]', '</u>', $ciag);
  11.  
  12.     // [pogrubienie]
  13.     $ciag = str_replace ('[pogrubienie]', '<b>', $ciag);
  14.     $ciag = str_replace ('[/pogrubienie]', '</b>', $ciag);
  15.  
  16.     // [rozmiar=\"x\"] (x = x pikseli)
  17.     $ciag = str_replace ('[rozmiar=\"', '<span style=\"font-size: ', $ciag);
  18.     $ciag = str_replace ('\"]', '\">', $ciag);
  19.     $ciag = str_replace ('[/rozmiar]', '</span>', $ciag);
  20.  
  21.     // [kolor=\"#FFFFFF\"] (#FFFFFF - kod szesnastkowy koloru)
  22.     $ciag = str_replace ('[kolor=\"', '<span style=\"color: ', $ciag);
  23.     $ciag = str_replace ('\"]', '\">', $ciag);
  24.     $ciag = str_replace ('[/kolor]', '</span>', $ciag);
  25.  
  26.     // [obraz=\"http://localhost/\" /] (zamiast http://localhost URL lub URI, pamiętaj o / na końcu!)
  27.     $ciag = str_replace ('[obraz=\"', '<img alt=\"\" src=\"', $ciag);
  28.     $ciag = str_replace ('\" /]', '\" />', $ciag);
  29.  
  30.     // [link=\"http://localhost/\"] (zamiast http://localhost URL lub URI)
  31.     $ciag = str_replace ('[link=\"', '<a href=\"', $ciag);
  32.     $ciag = str_replace ('[/link]', '</a>', $ciag);
  33.  
  34.     // [email=\"fipaj@poczta.onet.pl\"] (zamiast fipaj@poczta.onet.pl wpisz adres e-mail)
  35.     $ciag = str_replace ('[email=\"', '<a href=\"mailto:', $ciag);
  36.     $ciag = str_replace ('[/email]', '</a>', $ciag);
  37.  
  38.     // [gg=\"4953847\"] (zamiast 4953847 numer GG)
  39.     $ciag = str_replace ('[gg=\"', '<a href=\"gg:', $ciag);
  40.     $ciag = str_replace ('[/gg]', '</a>', $ciag);
  41.  
  42.     // [skype=\"fipaj_lokonet\"] (zamiast fipaj_lokonet swój skype_id)
  43.     $ciag = str_replace ('[skype=\"', '<a href=\"callto:', $ciag);
  44.     $ciag = str_replace ('[/skype]', '</a>', $ciag);
  45.  
  46.     return $ciag;
  47. }
  48.  
  49. print bbcode('ten tekst będzie [pogrubienie]pogrubiony[/pogrubienie], dodatkowo jak sie ktoś postara, to i [podkreslenie] podkreślony[/podkreslenie], zaś dla mistrzów w temacie, poleca sie rownież użycie [kursywa]ku
    rsywy[/kursywa]. a oto [link=\"link...\"]hiperłącze![/link]. [kolor=\"darkred\"]zdaje mi się, że bbcode działa![/kolor]'
    );
  50.  
  51. ?>


Ten post edytował Fipaj 28.02.2005, 14:55:28
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 14:11