UBB-codes

Gestart doorTgrm16 reacties32 weergaven

17 berichten · pagina 1 van 2

Tgrm

Lid · Topicstarter

Berichten
2.133
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo,

Ik heb hier een scriptje, bijv:

$reply_message = str_replace([b], <b>, $reply_message);
$reply_message = str_replace([/b], </b>, $reply_message);


Maar het probleem is dat als je bijvoorbeeld dit doet:

[b][/b][/b][/b][b][b]


Dat ik zou willen dat ze mooi worden afgesloten of dat ze iig niet door kunnen lopen.

Iemand die me hierbij kan helpen?

~tgrm
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
    $string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][b][b][b]bier!![/b][/b][/COLOR][COLOR= #007700];[/COLOR]
    
    [URL="http://www.php.net/preg_match_all"]preg_match_all[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$found[/COLOR][COLOR= #007700]);[/COLOR]
    
    [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$found[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]] as[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700])[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/preg_replace"]preg_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"<strong>$1</strong>"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700]);[/COLOR]
0
Tgrm

Lid · Topicstarter

Berichten
2.133
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Luukvdo schreef:
[COLOR= #0000BB]<?php
    $string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][b][b][b]bier!![/b][/b][/COLOR][COLOR= #007700];[/COLOR]
    
    [URL="http://www.php.net/preg_match_all"]preg_match_all[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$found[/COLOR][COLOR= #007700]);[/COLOR]
    
    [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$found[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]] as[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700])[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/preg_replace"]preg_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"<strong>$1</strong>"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700]);[/COLOR]
En daarna gewoon de string in de db zetten?
0
Berichten
9.969
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Tgrm schreef:
Eerdere citaten tonen
Luukvdo schreef:
[COLOR= #0000BB]<?php
    $string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][b][b][b]bier!![/b][/b][/COLOR][COLOR= #007700];[/COLOR]
    
    [URL="http://www.php.net/preg_match_all"]preg_match_all[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$found[/COLOR][COLOR= #007700]);[/COLOR]
    
    [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$found[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]] as[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700])[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/preg_replace"]preg_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"<strong>$1</strong>"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700]);[/COLOR]
En daarna gewoon de string in de db zetten?

Zou ik niet doen, altijd pas bij de output parsen...
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Robbert schreef:
Eerdere citaten tonen
Tgrm schreef:
Eerdere citaten tonen
Luukvdo schreef:
[COLOR= #0000BB]<?php
    $string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][b][b][b]bier!![/b][/b][/COLOR][COLOR= #007700];[/COLOR]
    
    [URL="http://www.php.net/preg_match_all"]preg_match_all[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$found[/COLOR][COLOR= #007700]);[/COLOR]
    
    [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$found[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]] as[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700])[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/preg_replace"]preg_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"<strong>$1</strong>"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700]);[/COLOR]
En daarna gewoon de string in de db zetten?
Zou ik niet doen, altijd pas bij de output parsen...

Dat dus. Je kan het best bij de input parsen maar ik raad het niet aan
0
Tgrm

Lid · Topicstarter

Berichten
2.133
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Luukvdo schreef:
Eerdere citaten tonen
Robbert schreef:
Eerdere citaten tonen
Tgrm schreef:
Eerdere citaten tonen
Luukvdo schreef:
[COLOR= #0000BB]<?php
    $string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][b][b][b]bier!![/b][/b][/COLOR][COLOR= #007700];[/COLOR]
    
    [URL="http://www.php.net/preg_match_all"]preg_match_all[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$found[/COLOR][COLOR= #007700]);[/COLOR]
    
    [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$found[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]] as[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700])[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/preg_replace"]preg_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"<strong>$1</strong>"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700]);[/COLOR]
En daarna gewoon de string in de db zetten?
Zou ik niet doen, altijd pas bij de output parsen...
Dat dus. Je kan het best bij de input parsen maar ik raad het niet aan

Maar met welke var geef ik de nieuwe output dan weer weer?
0
Berichten
9.969
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Tgrm schreef:
Eerdere citaten tonen
Luukvdo schreef:
Eerdere citaten tonen
Robbert schreef:
Eerdere citaten tonen
Tgrm schreef:
Eerdere citaten tonen
Luukvdo schreef:
[COLOR= #0000BB]<?php
    $string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][b][b][b]bier!![/b][/b][/COLOR][COLOR= #007700];[/COLOR]
    
    [URL="http://www.php.net/preg_match_all"]preg_match_all[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$found[/COLOR][COLOR= #007700]);[/COLOR]
    
    [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$found[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]] as[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700])[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/preg_replace"]preg_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"<strong>$1</strong>"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700]);[/COLOR]
En daarna gewoon de string in de db zetten?
Zou ik niet doen, altijd pas bij de output parsen...
Dat dus. Je kan het best bij de input parsen maar ik raad het niet aan
Maar met welke var geef ik de nieuwe output dan weer weer?

Door die echo dus...
Anders zou je die laatste echo kunnen vervangen met:
$bericht =
en dan $bericht echoën
0
Berichten
3.314
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Als je niet OOP werkt (wat ik wel aanraad maar wss te moeilijk is)
kun je dit doen:

[COLOR= #0000BB]<?php[/COLOR]
    
[URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] ubbThis[COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]){[/COLOR]

            
        [URL="http://www.php.net/preg_match_all"]preg_match_all[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$found[/COLOR][COLOR= #007700]);[/COLOR]
    
        [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$found[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]] as[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700]){[/COLOR]
            [URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/preg_replace"]preg_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"<strong>$1</strong>"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700]); 
            }    
}[/COLOR]
?>


Als je dan bijv de ubb code uit een nieuwsbericht genaamd $row[nieuwsbericht] wilt laten zien kun je dit doen:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] ubbThis[COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]nieuwsbericht[/COLOR][COLOR= #007700]]);[/COLOR]
?>
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dan zou ik wel die public voor function weghalen aangezien je ubbThis als functie aanroept en niet als functie in een class
0
Tgrm

Lid · Topicstarter

Berichten
2.133
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Tnx all,

En nja... OOP of niet. Ik hecht er nog niet veel waarde aan, eerst maar es zorgen dat alles werkt. smile
0
Berichten
3.314
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Luukvdo schreef:
Dan zou ik wel die public voor function weghalen aangezien je ubbThis als functie aanroept en niet als functie in een class
Idd, was ff in de war
Tgrm schreef:
Tnx all,

En nja... OOP of niet. Ik hecht er nog niet veel waarde aan, eerst maar es zorgen dat alles werkt. smile
Hmm als je dan toch OOP wilt gaan werken kun je dat beter meteen doen, scheelt een enorme hoop werk, anders moet je later praktisch opnieuw beginnen yummie
0
Tgrm

Lid · Topicstarter

Berichten
2.133
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
BUMP... kom er niet uit hoor.

Ben er nu weer es mee bezig maar krijg hem niet aan de praat.

Weergeven:

[COLOR= #0000BB]<?php
    $string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$rowreplys[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]reply_message[/COLOR][COLOR= #007700]];[/COLOR]
                                    [URL="http://www.php.net/preg_match_all"]preg_match_all[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$found[/COLOR][COLOR= #007700]);[/COLOR]
                                    [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$found[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]] as[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700])[/COLOR]
                                        [COLOR= #0000BB]$reply[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/preg_replace"]preg_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"<strong>$1</strong>"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700]);[/COLOR]
    ?>

    [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/nl2br"]nl2br[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$reply[/COLOR][COLOR= #007700]));[/COLOR] ?>


In de database:

[b]Test1[/b][/b][/b]Test2[b][b]Test3[b]


Er komt uit:

Test1[/b][/b]


Wat doe ik fout?

ps. nogal noob met preg en foreach sadley
0
Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Tgrm schreef:
BUMP... kom er niet uit hoor.

Ben er nu weer es mee bezig maar krijg hem niet aan de praat.

Weergeven:
[COLOR= #0000BB]<?php
    $string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$rowreplys[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]reply_message[/COLOR][COLOR= #007700]];[/COLOR]
                                    [URL="http://www.php.net/preg_match_all"]preg_match_all[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$found[/COLOR][COLOR= #007700]);[/COLOR]
                                    [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$found[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]] as[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700])[/COLOR]
                                        [COLOR= #0000BB]$reply[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/preg_replace"]preg_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"<strong>$1</strong>"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700]);[/COLOR]
    ?>

    [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/nl2br"]nl2br[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$reply[/COLOR][COLOR= #007700]));[/COLOR] ?>


In de database:

[b]Test1[/b][/b][/b]Test2[b][b]Test3[b]


Er komt uit:

Test1[/b][/b]


Wat doe ik fout?

ps. nogal noob met preg en foreach sadley
Kijk is naar de class van Bas, misschien vind je daar iets.
0
Tgrm

Lid · Topicstarter

Berichten
2.133
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Shahiem schreef:
Eerdere citaten tonen
Tgrm schreef:
BUMP... kom er niet uit hoor.
Ben er nu weer es mee bezig maar krijg hem niet aan de praat.

Weergeven:

[COLOR= #0000BB]<?php
    $string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$rowreplys[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]reply_message[/COLOR][COLOR= #007700]];[/COLOR]
                                    [URL="http://www.php.net/preg_match_all"]preg_match_all[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$found[/COLOR][COLOR= #007700]);[/COLOR]
                                    [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$found[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]] as[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700])[/COLOR]
                                        [COLOR= #0000BB]$reply[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/preg_replace"]preg_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"#[b](.*)[/b]#"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"<strong>$1</strong>"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$item[/COLOR][COLOR= #007700]);[/COLOR]
    ?>

    [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/nl2br"]nl2br[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$reply[/COLOR][COLOR= #007700]));[/COLOR] ?>


In de database:

[b]Test1[/b][/b][/b]Test2[b][b]Test3[b]


Er komt uit:

Test1[/b][/b]


Wat doe ik fout?

ps. nogal noob met preg en foreach sadley
Kijk is naar de class van Bas, misschien vind je daar iets.

Ben niet zo van de complete systemen / classes. Als iemand nog een werkende klene code heeft, graag. smile
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren