Precedente :: Successivo |
Autore |
Messaggio |
mdweb Dio maturo


Registrato: 18/12/07 16:59 Messaggi: 4412
|
Inviato: 05 Mar 2008 20:32 Oggetto: creare un BBCODE [Tutorial] |
|
|
Vediamo come creare uno script BBCODE che traduce [b],[i] ect. in HTML.Creare un nuovo file :
Codice: |
<?php
function bbcode_format ($str) {
return $str;
}
$str = htmlentities($str);
function bbcode_format ($str) {
$str = htmlentities($str);
$str = preg_replace ('/\[b\](.*?)\[\/b\]/is', '<strong>$1</strong>', $str);
$str = preg_replace ('/\[i\](.*?)\[\/i\]/is', '<em>$1</em>', $str);
$str = preg_replace ('/\[u\](.*?)\[\/u\]/is', '<u>$1</u>', $str);
return $str;
}
function bbcode_format ($str) {
$str = htmlentities($str);
$simple_search = array(
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is'
);
$simple_replace = array(
'<strong>$1</strong>',
'<em>$1</em>',
'<u>$1</u>'
);
$str = preg_replace ($simple_search, $simple_replace, $str);
return $str;
} |
Questo è lo script che serve a tradurre BBCODE in HTML però se non ci ricordiamo di chiudere questi tag ci si scombussolerà il layout perciò dobbiamo aggiungere questo codice:
Codice: | Funzione bbcode_quote ($ str) (
$open = '<blockquote>' ; $ Open = '<blockquote>';
$close = '</blockquote>' ; $ Chiudi = '</ blockquote>';
// How often is the open tag? / / Come spesso è il tag di apertura?
preg_match_all ( '/ \[ quote \] /i' , $str , $matches ) ; Preg_match_all ( '/ \ [quote \] / i', $ str, $ matches);
$opentags = count ( $matches [ '0' ] ) ; Opentags $ = count ($ matches ['0 ']);
// How often is the close tag? / / Come spesso è il tag di chiusura?
preg_match_all ( '/ \[ \/ quote \] /i' , $str , $matches ) ; Preg_match_all ( '/ \ [\ / quote \] / i', $ str, $ matches);
$closetags = count ( $matches [ '0' ] ) ; Closetags $ = count ($ matches ['0 ']);
// Check how many tags have been unclosed / / Check quanti sono stati aperti i tag
// And add the unclosing tag at the end of the message / / E unclosing aggiungere il tag alla fine del messaggio
$unclosed = $opentags - $closetags ; $ = $ Aperti opentags - $ closetags;
for ( $i = 0 ; $i < $unclosed ; $i ++ ) { For ($ i = 0; $ i <$ aperti; $ i + +) (
$str .= '</blockquote>' ; $ Pag .= '</ blockquote>';
} )
// Do replacement / / A sostituzione
$str = str_replace ( '[ quote]' , $open , $str ) ; $ Str = str_replace ( '[citazione]', $ aperta, $ str);
$str = str_replace ( '[ /quote]' , $close , $str ) ; $ Str = str_replace ( '[/ quote]', $ chiudere, $ str);
return $str ; Return $ str;
} )
?>
|
Ciao |
|
Top |
|
 |
Zeus Amministratore


Registrato: 21/10/00 02:01 Messaggi: 13287 Residenza: San Junipero
|
Inviato: 05 Mar 2008 21:26 Oggetto: |
|
|
Citazione: | Come spesso è il tag di chiusura? |
Ma chi l'ha tradotto, Altavista? |
|
Top |
|
 |
mdweb Dio maturo


Registrato: 18/12/07 16:59 Messaggi: 4412
|
Inviato: 05 Mar 2008 21:31 Oggetto: |
|
|
mi sono imrogliato con la tastiera mentre scriveo come tradotto....???
Questo l'ho imaprato a scuola  |
|
Top |
|
 |
Zeus Amministratore


Registrato: 21/10/00 02:01 Messaggi: 13287 Residenza: San Junipero
|
Inviato: 05 Mar 2008 22:23 Oggetto: |
|
|
capisco... |
|
Top |
|
 |
mdweb Dio maturo


Registrato: 18/12/07 16:59 Messaggi: 4412
|
Inviato: 05 Mar 2008 23:00 Oggetto: |
|
|
probabilemnte è colpa dei prof non mia  |
|
Top |
|
 |
Typhoon90 Dio maturo


Registrato: 01/06/06 16:17 Messaggi: 1019 Residenza: Vivere per niente o morire per qualcosa. Scegli tu.
|
Inviato: 05 Mar 2008 23:07 Oggetto: |
|
|
invece io non capisco
cosa intendi comunicare con quel link? |
|
Top |
|
 |
Zeus Amministratore


Registrato: 21/10/00 02:01 Messaggi: 13287 Residenza: San Junipero
|
Inviato: 06 Mar 2008 02:15 Oggetto: |
|
|
... che i prof di mdweb probabilmente si sono ispirati a qualcuno quando hanno scritto quella pagina. |
|
Top |
|
 |
mdweb Dio maturo


Registrato: 18/12/07 16:59 Messaggi: 4412
|
Inviato: 06 Mar 2008 14:30 Oggetto: |
|
|
io non lo so non ho fatto altro che copiare quello che i prof ci hanno sipegato a scuola....mi dispiace se non mi credi...  |
|
Top |
|
 |
|