Scheldwoorden weghalen [BELONING]

Gestart doorDylan2 reacties22 weergaven

3 berichten · pagina 1 van 1

Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Hoi,

Ik ben bezig om alle scheld woorden uit de zinnen te verwijderen en om daarna een melding er van te maken. Ik heb tot nu dit:

[COLOR= #0000BB]<?php
$words[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]yolo[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]scheld[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$found[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/COLOR]

[URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$words[/COLOR] [COLOR= #007700]AS[/COLOR] [COLOR= #0000BB]$word[/COLOR][COLOR= #007700]) {[/COLOR]
    
    [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]r[/COLOR][COLOR= #007700]] =[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000].[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]r[/COLOR][COLOR= #007700]]);[/COLOR]
    [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]r[/COLOR][COLOR= #007700]] =[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]-[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]r[/COLOR][COLOR= #007700]]);[/COLOR]
    [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]r[/COLOR][COLOR= #007700]] =[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]<[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]r[/COLOR][COLOR= #007700]]);[/COLOR]
    [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]r[/COLOR][COLOR= #007700]] =[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]>[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]r[/COLOR][COLOR= #007700]]);[/COLOR]
    [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]r[/COLOR][COLOR= #007700]] =[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000],[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]r[/COLOR][COLOR= #007700]]);[/COLOR]
    
    
    [COLOR= #0000BB]$find[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/strpos"]strpos[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$word[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]r[/COLOR][COLOR= #007700]]);[/COLOR]

    
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$find[/COLOR] [COLOR= #007700]===[/COLOR] true[COLOR= #007700]) {[/COLOR]
        
        [COLOR= #0000BB]$found[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #0000BB]$word[/COLOR][COLOR= #007700];
        
    }[/COLOR]
        
[COLOR= #FF8000]//unset($find);[/COLOR]
            
[COLOR= #007700]}[/COLOR]

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$found[/COLOR][COLOR= #007700]) !=[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]) {[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]ja[/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]nee[/COLOR][COLOR= #007700];
}[/COLOR]




?>


Stel de GET waarde is yolo die staat in de array, maar dan zegt het script gewoon nee?

Wie dit oplost krijgt van mij 0,05 punten.

Alvast heel erg bedankt.
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
$find = strpos($word, $_GET[r]);

moet je zo doen:

$find = stripos($_GET[r], $word);

Ik gebruik de functie [func]stripos[/func], zodat hij ook YOlO en YolO herkent etc.. Je had ook de argumenten verkeerd ingevuld, want als eerste argument moet je de tekst zetten, en als tweede argument het zoekwoord

Ook moet dat $find === true anders, omdat stripos nooit true returnt, hij kan alleen een getal of false returnen. Jij wilt checken of het er in staat, dus dat kun je doen door te controleren of $find niet gelijk staat aan false, en ook geen 0 is.

$find !== FALSE
Dubbel = omdat hij 0 anders ook als false ziet, als $_GET[r] begint met yolo, staat het op positie 0, en denkt hij anders dat het er niet in staat.
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Sjoerd schreef:
$find = strpos($word, $_GET[r]);

moet je zo doen:

$find = stripos($_GET[r], $word);

Ik gebruik de functie [func]stripos[/func], zodat hij ook YOlO en YolO herkent etc.. Je had ook de argumenten verkeerd ingevuld, want als eerste argument moet je de tekst zetten, en als tweede argument het zoekwoord

Ook moet dat $find === true anders, omdat stripos nooit true returnt, hij kan alleen een getal of false returnen. Jij wilt checken of het er in staat, dus dat kun je doen door te controleren of $find niet gelijk staat aan false, en ook geen 0 is.

$find !== FALSE
Dubbel = omdat hij 0 anders ook als false ziet, als $_GET[r] begint met yolo, staat het op positie 0, en denkt hij anders dat het er niet in staat.
Thanks, weer wat geleerd, en het werkt nu ook. Je 0,05 komen naar je toe biggrin
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