Ugh!
I created a tiny 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'
;
=========================
And I've tried putting this all together, but just can not figure out what is causing the Error on LINE 23 ... or exactly what to do if I simply want to further process $text (once any 'badword(s)' may have been removed:
<?
?>
<html>
<head></head>
<body>
<?
if (isset($_POST['submit'])) {
$text = $_POST['text'];
echo "$test"; // 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)){
$badwords[] = $row['badword'];
if(!$result) {
echo "Query not executed successfully.";
exit;
} // end if $result
$pattern = implode('|', $badwords[]); // LINE 23 ERROR
if (preg_match("/$pattern/i", $text) {
echo "badword error";
} // end if $pattern
} // end isset
?>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<p>Enter Some Text:<br>
Text: <input type="text" name="text" size="20" maxlength="50"><br><br>
<input type="submit" name="submit" value="SUBMIT"></p>
</form>
</body>
</html>
<?
?>
"Help!" - Thanks.