return filtered results to page

Hi there,

I’m a total n00b when it comes to PHP, so you’ll have to pardon my ignorance. I have a basic foundation in javascript/html/css/jquery so I’m not completely uninitiated… Essentially what I want to do is implement the following script:

[php]

<? // BadWordFilter // This function does all the work. If $replace is 1 it will replace all bad words // with the wildcard replacements. If $replace is 0 it will not replace anything. // In either case, it will return 1 if it found bad words or 0 otherwise. // Be sure to fill the $bads array with the bad words you want filtered. FUNCTION BadWordFilter(&$text, $replace){ // fill this array with the bad words you want to filter and their replacements $bads = ARRAY ( ARRAY("butt","b***"), ARRAY("poop","p***"), ARRAY("crap","c***") ); IF($replace==1) { //we are replacing $remember = $text; FOR($i=0;$i<sizeof($bads);$i++) { //go through each bad word $text = EREGI_REPLACE($bads[$i][0],$bads[$i][1],$text); //replace it } IF($remember!=$text) RETURN 1; //if there are any changes, return 1 } ELSE { //we are just checking FOR($i=0;$i

[/php]

I will have a page with an html form, one text field and a submit button. I’m guessing that I need to save the above script to a PHP file, and set that file as the action for the submit button in the html form. The problem is - how do I return the filtered results to the next page?

Thanks in advance!

You can form with field on page1, and form’s action set to page2. And have all the filtering done by php code on page2 - just before generating html page to send to browser. For example, you have text field in the form on page1 named mytext. Your page2 structure:

page2.php[php]<?php
if(isset($_POST[“mytext”])){
$any = BadWordFilter($_POST[“mytext”],1);
echo $_POST[“mytext”];
}
else{
// no text - back to page1.php
header(‘Location: page1.php’);
exit;
}
?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service