Str_replace herhaalt zich

Gestart doorSanderc5 reacties22 weergaven

6 berichten · pagina 1 van 1

Sanderc

Lid · Topicstarter

Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallon,

Ik zit met nog een klein probleempje;

namelijk, als ik "a" typ:

$vervangers = array(az0d,sd5qs,s07tj,pp55,ol41);


a = az0d

dan gaat hij de "d" uit az0d vervangen naar "pp55"

Dus hij replaced eigenlijk NOG eens
Hoe zorg ik dat hij dat niet doet?

Check onderschrift voor link
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Post de relevante code dan eens, ik gok dat je het met een foreach loop hebt gedaan terwijl str_replace zelf prima met arrays om kan gaan.

Am I right?
0
Sanderc

Lid · Topicstarter

Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Nee, geen foreach redface
Dit is de code;

[COLOR= #0000BB]<?php
$datum[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/date"]date[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"d/m/Y H:i:s"[/COLOR][COLOR= #007700]);[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<h2> &copy; Shizo bèta</h2><h4> => Develop mode entered at [/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$datum[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]</h4>[/COLOR][COLOR= #007700];[/COLOR] 


[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_METHOD[/COLOR][COLOR= #007700]]==[/COLOR] [COLOR= #DD0000]"POST"[/COLOR][COLOR= #007700])
{[/COLOR]
[COLOR= #0000BB]$letters[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]a[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]b[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]c[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]d[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]e[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$vervangers[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]az0d[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]sd5qs[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]s07tj[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]pp55[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]ol41[/COLOR][COLOR= #007700]);[/COLOR]

    [COLOR= #0000BB]$woord[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/strtolower"]strtolower[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]woord[/COLOR][COLOR= #007700]]);[/COLOR]
    
    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wat[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]"codeer"[/COLOR][COLOR= #007700])
    {[/COLOR]    
        
    [COLOR= #0000BB]$woordo[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$letters[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$vervangers[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$woord[/COLOR][COLOR= #007700]);[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$woordo[/COLOR][COLOR= #007700];
    }[/COLOR]
    [URL="http://www.php.net/elseif"]elseif[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wat[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]"ontcijfer"[/COLOR][COLOR= #007700])
    {[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<b>ERROR: Function Fail // De functie werkt nog niet (helemaal)</b><br/>[/COLOR][COLOR= #007700];[/COLOR]
        [COLOR= #0000BB]$woordo[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$vervangers[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$letters[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$woord[/COLOR][COLOR= #007700]);[/COLOR]
    
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$woordo[/COLOR][COLOR= #007700];
    }[/COLOR]
    [URL="http://www.php.net/else"]else[/URL]
    [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000] er is iets mislukt met het kiezen tussen coderen of incijferen. Contacteer de beheerder[/COLOR][COLOR= #007700];
    }
    
        
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
?>
<form action="#" method="post">
    Woord: <input type="text" name="woord">
    <select name="wat">
        <option name="codeer" value="codeer">Codeer</option>
        <option name="ontcijfer" value="ontcijfer">Ontcijfer</option>
    </select>
        
    <input type="submit" value="Hash">
    
    <b>De "Ontcijfer" functie werkt niet (helemaal)</b>
</form>
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]}[/COLOR]
?>
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Oh ik zie het ja, "Because str_replace() replaces left to right, it might replace a previously inserted value when doing multiple replacements. See also the examples in this document." yummie
Dan zou je dat moeten omzeilen; de opgegeven string karakter voor karakter aflopen en dan in een andere variabele de gecodeerde versie ervan maken.

Denk dat het niet echt handiger kan?
0
Sanderc

Lid · Topicstarter

Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Lennard schreef:
Oh ik zie het ja, "Because str_replace() replaces left to right, it might replace a previously inserted value when doing multiple replacements. See also the examples in this document." yummie
Dan zou je dat moeten omzeilen; de opgegeven string karakter voor karakter aflopen en dan in een andere variabele de gecodeerde versie ervan maken.

Denk dat het niet echt handiger kan?
Dus hem exploden en dan zo in een nieuwe string zetten? Dat gaat toch een massa code geven?
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Sanderc schreef:
Eerdere citaten tonen
Lennard schreef:
Oh ik zie het ja, "Because str_replace() replaces left to right, it might replace a previously inserted value when doing multiple replacements. See also the examples in this document." yummie
Dan zou je dat moeten omzeilen; de opgegeven string karakter voor karakter aflopen en dan in een andere variabele de gecodeerde versie ervan maken.

Denk dat het niet echt handiger kan?

Dus hem exploden en dan zo in een nieuwe string zetten? Dat gaat toch een massa code geven?
Hoezo?

[COLOR= #0000BB]<?php
$string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]ditwordtencrypted[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/for"]for[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$i[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700];[/COLOR][COLOR= #0000BB]$i[/COLOR][COLOR= #007700]<[/COLOR][URL="http://www.php.net/strlen"]strlen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]);[/COLOR][COLOR= #0000BB]$i[/COLOR][COLOR= #007700]++) {[/COLOR]
[COLOR= #0000BB]$string[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$i[/COLOR][COLOR= #007700]] =[/COLOR] [COLOR= #DD0000]vervanging van [/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$i[/COLOR][COLOR= #007700]];
}[/COLOR]
?>


ofzo?
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