pojr Posted June 30, 2008 Share Posted June 30, 2008 For if statements, well lets say my post content is under $post, and I don't want this content to have any curse words. If I were to do: if ( $post == gris ) { echo "<h1>Error!</h1> Gris is a naughty word. I cannot let you say that on this site!"; It would vary. If I posted just gris on the post line, I would get the error message, but posted I like gris, the post would go through. I know the if == is sharp, so is there a way for $post to register one word in the post? Thanks a bunch in return. Quote Link to comment https://forums.phpfreaks.com/topic/112675-solved-important-question-about-php/ Share on other sites More sharing options...
br0ken Posted June 30, 2008 Share Posted June 30, 2008 Do you mean something like this... <?php $var = "This is a string. Strings are bad, so is the word is."; if (!(strpos($var, "string") === false)) { echo "The word 'string' is a naughty word!<br />"; } ?> This way will check if the word is found anywhere in the string. You could also use str_replace() to remove any occurences of bad words and replace them with something else (*'s for instance). Quote Link to comment https://forums.phpfreaks.com/topic/112675-solved-important-question-about-php/#findComment-578645 Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 yes there is. first of all. Theres a minor mistake. if ( $post == 'gris' ) { Quote Link to comment https://forums.phpfreaks.com/topic/112675-solved-important-question-about-php/#findComment-578646 Share on other sites More sharing options...
pojr Posted June 30, 2008 Author Share Posted June 30, 2008 From testing, quotes only seem to matter if there is a space in the word. Yeah however, that was what I was looking for. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/112675-solved-important-question-about-php/#findComment-578655 Share on other sites More sharing options...
trq Posted June 30, 2008 Share Posted June 30, 2008 From testing, quotes only seem to matter if there is a space in the word. Nope, all strings need to be surrounded in quotes. Turn error reporting on and try again. Quote Link to comment https://forums.phpfreaks.com/topic/112675-solved-important-question-about-php/#findComment-578657 Share on other sites More sharing options...
pojr Posted June 30, 2008 Author Share Posted June 30, 2008 Error reporting? Quote Link to comment https://forums.phpfreaks.com/topic/112675-solved-important-question-about-php/#findComment-578660 Share on other sites More sharing options...
trq Posted June 30, 2008 Share Posted June 30, 2008 You should have this at the top of all script while developing. <?php error_reporting(E_ALL) ; ini_set('display_errors','1'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/112675-solved-important-question-about-php/#findComment-578662 Share on other sites More sharing options...
pojr Posted June 30, 2008 Author Share Posted June 30, 2008 Sounds good, but this script is not working. <?php if (!(strpos($pst, "<b>" ) === true)) { if (!(strpos($pst, "</b>" ) === false)) { $htmlallowance = "negative"; } } ?> The post in my forums still go through then I don't add a </b> when posting <b>. Quote Link to comment https://forums.phpfreaks.com/topic/112675-solved-important-question-about-php/#findComment-578671 Share on other sites More sharing options...
TheBigRedStapler Posted June 30, 2008 Share Posted June 30, 2008 Would this work? # not tested, don't have a server running or setup right now foreach ($_POST as $post) { foreach ($naughtyWord as $n => $v) { if (strpos($nw, $pos) !== false) { echo "You said $v in $n!"; } } HTH Quote Link to comment https://forums.phpfreaks.com/topic/112675-solved-important-question-about-php/#findComment-578674 Share on other sites More sharing options...
pojr Posted June 30, 2008 Author Share Posted June 30, 2008 Oh wait, I just figured it out. Thanks though. http://forums.dan92.yfma.com/ should work now. Quote Link to comment https://forums.phpfreaks.com/topic/112675-solved-important-question-about-php/#findComment-578675 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.