ziedinjsh Posted September 4, 2013 Report Share Posted September 4, 2013 Veidoju kko līdzīgu bad word filtram.. šinī gadījumā nevis aizvieto ar kaut ko bet paziņo ir bad word vai nav. <?php include('dbase.php'); $data = 'kjhedkedhewlkejkswp pis wjeflk'; global $pre; $sql = mysql_query("SELECT * FROM bad_words") or die(mysql_error()); if (mysql_num_rows($sql) > 0) { while($rs = mysql_fetch_assoc($sql)) { $bad_words[] = $rs['word']; } } $noBadWordsFound = true; foreach ($bad_words as $word) { if (preg_match('/'.$word.'/', $data)) { $noBadWordsFound = false; break; } } if ($noBadWordsFound) { echo 'nav'; } else { echo 'ir'; } ?> nepieciešamo funkciju viņš dar, bet ir vēl šāda lieta kā: Warning: preg_match(): Compilation failed: nothing to repeat at offset 0 in /home/mydraftn/public_html/process/test.php on line 17Warning: preg_match(): Compilation failed: nothing to repeat at offset 0 in /home/mydraftn/public_html/process/test.php on line 17Warning: preg_match(): Compilation failed: nothing to repeat at offset 0 in /home/mydraftn/public_html/process/test.php on line 17Warning: preg_match(): Compilation failed: nothing to repeat at offset 0 in /home/mydraftn/public_html/process/test.php on line 17Warning: preg_match(): Compilation failed: nothing to repeat at offset 3 in /home/mydraftn/public_html/process/test.php on line 17 es tikai nevaru saprast kas man jāpārveido vai kādi simboli ir jāliek šajā vietā '/'.$word.'/' Paldies jau iepriekš! Quote Link to comment Share on other sites More sharing options...
php newbie Posted September 4, 2013 Report Share Posted September 4, 2013 labāk izmanto http://php.net/manual/en/function.strpos.php Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted September 4, 2013 Author Report Share Posted September 4, 2013 (edited) kā tu biji to domājis? Man neiet ar to strpos <?php include('dbase.php'); $data = 'kjhedkedhewlkejkswp pis wjeflk'; $sql = mysql_query("SELECT * FROM bad_words") or die(mysql_error()); if (mysql_num_rows($sql) > 0) { while($rs = mysql_fetch_assoc($sql)) { $bad_words[] = $rs['word']; } } $noBadWordsFound = true; foreach ($bad_words as $word) { if(strpos($data, $word)){ $noBadWordsFound = false; break; } } if ($noBadWordsFound) { echo 'nav'; } else { echo 'ir'; } ?> Edited September 4, 2013 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
jurchiks Posted September 4, 2013 Report Share Posted September 4, 2013 (edited) mysql_query("SELECT * FROM bad_words") or die(mysql_error()); Tavai zināšanai, ja šis query returnos empty array(kas ne vienmēr ir erors), tavs kods "nomirs" bez erora. array() == false Edited September 4, 2013 by jurchiks Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted September 4, 2013 Author Report Share Posted September 4, 2013 ja es $word vietā izmantoju kādu konkrētu vārdu tad strādā Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted September 4, 2013 Author Report Share Posted September 4, 2013 mysql_query("SELECT * FROM bad_words") or die(mysql_error()); Tavai zināšanai, ja šis query returnos empty array(kas ne vienmēr ir erors), tavs kods "nomirs" bez erora. array() == false šādi ir labāk $sql = mysql_query("select word from bad_words") or die(mysql_error()); ? Quote Link to comment Share on other sites More sharing options...
jurchiks Posted September 4, 2013 Report Share Posted September 4, 2013 (edited) ... 708 posti un tu pat šitādas lietas nezini? Nē, tā nav labāk (izņemot to, ka tu definēji izmantotās kolonnas nosaukumu), tas neko nemainīs. Pirmkārt jau sen laiks pārmesties uz mysqli vai PDO, mysql extension ir deprecated un drīz tiks izdzēsts no PHP. http://www.php.net/manual/en/mysqli.quickstart.connections.php http://www.php.net/manual/en/mysqli.quickstart.statements.php Un vēl, priekš kam tu loopo cauri resultsetam, glabā kolonnu masīvā, un pēc tam loopo cauri tam masīvam tā vietā, lai izmantotu masīvu pa tiešo? $badWordsFound = false; while ($rs = mysql_fetch_assoc($sql)) { if (strpos($data, $rs['word']) !== false) // strpos var atgriezt arī 0, kas skaitās false, tāpēc jāpārbauda ar !== false { $badWordsFound = true; } } Edited September 4, 2013 by jurchiks Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted September 4, 2013 Author Report Share Posted September 4, 2013 ar mysql_fetch_assoc nestradā, strādā ar mysql_fetch_array. Par mysqli neatradu kā pieslēgties konkrētai datubāzes tabulai vai datubāzai Quote Link to comment Share on other sites More sharing options...
jurchiks Posted September 5, 2013 Report Share Posted September 5, 2013 (edited) Par mysqli neatradu kā pieslēgties konkrētai datubāzes tabulai vai datubāzei $mysqli = new mysqli("localhost", "user", "password", "database"); Kā arī standarta "USE xyz" query. Tabulām principā "nepieslēdzas". Edited September 5, 2013 by jurchiks Quote Link to comment 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.