Jump to content
php.lv forumi

Compilation failed


ziedinjsh

Recommended Posts

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 17

Warning: preg_match(): Compilation failed: nothing to repeat at offset 0 in /home/mydraftn/public_html/process/test.php on line 17

Warning: preg_match(): Compilation failed: nothing to repeat at offset 0 in /home/mydraftn/public_html/process/test.php on line 17

Warning: preg_match(): Compilation failed: nothing to repeat at offset 0 in /home/mydraftn/public_html/process/test.php on line 17

Warning: 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š!

Link to comment
Share on other sites

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 by ziedinjsh
Link to comment
Share on other sites

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()); ?

Link to comment
Share on other sites

...

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 by jurchiks
Link to comment
Share on other sites

 

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 by jurchiks
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...