[PHP] Preg_replace - $1

Gestart doorOne2xs9 reacties31 weergaven

10 berichten · pagina 1 van 1

One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Hoi,

Ik wil een nieuwe UBB tag toevoegen, alleen dan staan er bepaalde namen in $1 en dan wil ik if(login::getID() == $1)
{
//Actie uitvoeren
}
doen, alleen dan geeft hij een error, logisch omdat een variabele niet mag starten met een getal.

Hoe krijg ik dit dan wel werken?
Wat ik wil is

Ik heb een spoiler tag, ongeveer gelijk aan die van One2xs, en dan wil ik dat als je

[user=xjessex]Hoi[/user]

doet, dat je een soort spoiler krijgt, die alleen zichtbaar is voor de gebruiker xjessex, en voor meerdere gebruikers dan
[user=xjessex, naam2]Hoi[/user]

Dat meerdere namen kan ik doen middels een foreach en dan explode op de komma, alleen hoe krijg ik [user=DEZE INHOUD] in een php variabele?
Dus hij staat nu in $1, alleen ik wil dat ik er gewoon een normale php variabele van kan maken zodat ik hem ook anders kan gebruiken.

Groet,
Jesse
0
Berichten
6.144
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Waarom niet explode?
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
explode doe ik dan ook, maar ik kan $1 niet explode aangezien het geen geldige php variabele is?

toevoeging op 24 april 2012, 14:39:49:
Ik heb nu

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] User2[COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]){[/COLOR]
        [URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"(([user2=(.+?)](.+?)[/user2])|([user2](.+?)[/user2]))is"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700])) {[/COLOR]
            [COLOR= #0000BB]$users[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/preg_replace"]preg_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"([user2=(.+?)](.+?)[/user2])is"[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]$1[/COLOR] [COLOR= #007700],[/COLOR][COLOR= #0000BB]$users[/COLOR][COLOR= #007700]);[/COLOR] 
            [COLOR= #0000BB]$users2[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/explode"]explode[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]","[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$users[/COLOR][COLOR= #007700]);[/COLOR]
            [COLOR= #0000BB]$mijnNaam[/COLOR] [COLOR= #007700]=[/COLOR] getInfoByID[COLOR= #007700]([/COLOR][COLOR= #DD0000]username[/COLOR][COLOR= #007700],[/COLOR] login[COLOR= #007700]::[/COLOR]getID[COLOR= #007700]());[/COLOR]
            [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$users2[/COLOR] [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$naam[/COLOR][COLOR= #007700])
            {[/COLOR]
                [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$naam[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]$mijnNaam[/COLOR][COLOR= #007700])
                {[/COLOR]
                    [COLOR= #0000BB]$string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]hoi[/COLOR][COLOR= #007700];
                }
            }
        }[/COLOR]
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700];
    }[/COLOR]
?>


Dat moet dan simpel gezegd hoi terug geven als jouw gebruikersnaam in de tag staat dus:
[user2=xjessex]djdfd[/user2]
Dan zou ik dus hoi moeten zien en jullie niet..

toevoeging op 24 april 2012, 14:40:13:
alleen als ik dat gebruik, dan laad de webpagina daar niet meer confused.
0
Berichten
2.692
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Kijk eens naar de functie preg_replace_callback biggrin
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Hij werkt nu, alleen hij pakt er maar 1 en die controleert hij..

En volgens mij alleen de laatste

toevoeging op 24 april 2012, 16:30:42:

[COLOR= #0000BB]<?php[/COLOR]
 [URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] User2[COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]){[/COLOR]
        [URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"(([user2=(.+?)](.+?)[/user2])|([user2](.+?)[/user2]))is"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700])) {[/COLOR]
            [COLOR= #0000BB]$users[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/preg_replace"]preg_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"([user2=(.+?)](.+?)[/user2])is"[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]$1[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700]);[/COLOR] 
            [COLOR= #0000BB]$users2[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/explode"]explode[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]","[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$users[/COLOR][COLOR= #007700]);[/COLOR]
            [COLOR= #0000BB]$mijnNaam[/COLOR] [COLOR= #007700]=[/COLOR] getInfoByID[COLOR= #007700]([/COLOR][COLOR= #DD0000]username[/COLOR][COLOR= #007700],[/COLOR] login[COLOR= #007700]::[/COLOR]getID[COLOR= #007700]());[/COLOR]
           [COLOR= #FF8000]// foreach($users2 as $naam)
           // {[/COLOR]
                [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strtolower"]strtolower[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$users[/COLOR][COLOR= #007700]) ==[/COLOR] [URL="http://www.php.net/strtolower"]strtolower[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$mijnNaam[/COLOR][COLOR= #007700]))
                {[/COLOR]
                    [COLOR= #0000BB]$string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]Jij mag dit zien :D[/COLOR][COLOR= #007700];
                }[/COLOR]
                [URL="http://www.php.net/else"]else[/URL]
                [COLOR= #007700]{[/COLOR]
                    [COLOR= #0000BB]$string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]Dit bericht is verborgen voor jou :D[/COLOR][COLOR= #007700];
                }[/COLOR]
           [COLOR= #FF8000]// }[/COLOR]
        [COLOR= #007700]}[/COLOR]
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700];
    }[/COLOR]
?>
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
preg_match, en vervolgens pas preg replace?
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Hoe moet het dan? bloosIk ben niet echt een expert in die preg dingen sadley
0
Berichten
6.485
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Preg_match($search, $file, $matches)

Matches[0] geeft $1
0
One2xs

Bot · Topicstarter

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Werkt niet..

toevoeging op 24 april 2012, 181354:
Ik heb hem nu werkend, alleen hij pakt hem maar 1 keer, en het moet juist op alle tags in dat bericht.
0
Berichten
6.485
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
preg_match_all
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