This is the best subject I could think of, and believe this is beyond the current thread in the Newbie Help section.
I've gotten this 'badword' filter thing to work part way and it will now replace the 1st 'dern' (MySQL list) badword with a smilie text.
However, it won't work on the 2nd or 3rd words in my test DB, and get the following error in every case:
Fatal error: [] operator not supported for strings on line 32
So it appears I have some kind of Array Conversion Problem.
After hours of trying different things, I am in need of some experienced coding help!!!
<?
?>
<html>
<head></head>
<body>
<?
function filterwords($test, $replacewith=":-)") {
global $allwords;
global $badwords;
global $text;
$badwords = implode("|", $badwords);
$allwords = explode(" ", $text);
for($j=0;$j<count($badwords);$j++) {
for($i=0;$i<count($allwords);$i++) {
if(is_int(strpos(strtolower($allwords[$i]), $badwords[$j]))) {
$text = eregi_replace($allwords[$i], $replacewith, stripslashes($text));
}
}
}
return $text;
}
if (isset($_POST['submit'])) { // start isset if
$text = $_POST['text'];
echo "Original Text: $text<br>"; // For Testing
$dbcnx = @mysql_connect('localhost', 'me', '');
mysql_select_db('bwfilter');
$sql = "SELECT badword FROM badwords";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)){ // start $sql if
$badwords[] = $row['badword']; // <-------------LINE 32 ERROR
if(!$result) { // start $result if
echo "Query not executed successfully.";
exit;
} // end if $result
$text = filterwords($text,":-)");
echo "Filtered Text: $text";
} // end $sql if
} // end isset if
?>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<p>Enter Some Text:<br>
Text: <input type="text" name="text" size="30" maxlength="30"><br><br>
<input type="submit" name="submit" value="SUBMIT"></p>
</form>
</body>
</html>
<?
?>
Here is the SQL for the test 'badwords' DB:
====================
-- DATABASE = bwfilter
DROP DATABASE if exists bwfilter;
CREATE DATABASE bwfilter;
-- TABLE = badwords
drop table if exists badwords;
CREATE TABLE badwords (
ID int not null auto_increment primary key,
badword varchar(30) not null
);
INSERT INTO badwords SET
badword='dern'
;
INSERT INTO badwords SET
badword='carp'
;
INSERT INTO badwords SET
badword='yowl'
;
====================
Thank you very much.