PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ra
Forum Commoner
Posts: 58 Joined: Fri Mar 25, 2005 4:25 pm
Post
by ra » Fri Apr 15, 2005 9:21 am
I have a meta search engine that displays recent search queries:
http://www.sodora.com/queries.html
As you can tell, there are a lot of 'naughty' searches being submitted.
I fear that Google will assume my site to be adult-related and cut off my adwords stream.
I'm trying to remove words from a predefined list, but I can't seem to be able to get it done. Any thoughts?
Code: Select all
<?
function format_term($term) {
$term = str_replace('-','~~',$term);
return str_replace(' ','-',$term);
}
$res = mysql_query("SELECT * FROM $querytable ORDER BY q_id DESC") or die(mysql_error());
$bad_words = array('pthc rompl ranchi pthc pthc ranchi board', 'melissa midwest', 'melissa midwest movies');
$pattern = '%'.preg_quote(implode('|', $bad_words)).'%i';
if (preg_match($pattern, $searchstring)) {
do_insert();
}
while (($line = mysql_fetch_assoc($res)) && strlen(ob_get_contents()) < 95*1024) {
echo "<a href='".constant('dir')."search/".format_term($line['q_query'])."'>".$line['q_query']."</a><br>";
}
?>
</div>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Apr 15, 2005 9:40 am
you may want to look at the pattern you are generating.. hint: you have the order of operations mixed up.
ra
Forum Commoner
Posts: 58 Joined: Fri Mar 25, 2005 4:25 pm
Post
by ra » Sat Apr 16, 2005 10:41 pm
so how should i restructure?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Apr 17, 2005 6:46 am
look at what $pattern turns out to be.
ra
Forum Commoner
Posts: 58 Joined: Fri Mar 25, 2005 4:25 pm
Post
by ra » Sun Apr 17, 2005 10:54 am
I'm afraid I don't follow... could you expand on that?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Apr 17, 2005 12:53 pm
echo $pattern.
look at the regex logic you request in it
fix your order of operations.
ra
Forum Commoner
Posts: 58 Joined: Fri Mar 25, 2005 4:25 pm
Post
by ra » Sun Apr 17, 2005 1:46 pm
1. echo $pattern.
Are you saying there is something wrong with my echo pattern?
2. look at the regex logic you request in it
What is regex logic?
3. fix your order of operations.
How?
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sun Apr 17, 2005 2:23 pm
Code: Select all
while (($line = mysql_fetch_assoc($res)) && strlen(ob_get_contents()) < 95*1024) {
Look carefully at your brackets.
ra
Forum Commoner
Posts: 58 Joined: Fri Mar 25, 2005 4:25 pm
Post
by ra » Mon Apr 18, 2005 1:25 pm
WHat about the brackets? What would it take to get a straight answer?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Apr 18, 2005 7:39 pm
you've gotten several straight answers to errors in your code. Count the open and closing parens in Jcart's post.
Next, if you understand some of the fundamentals of regex, you'll see that you have errors in your pattern for what you intended it to be.
And I'm done trying to help on that.
ra
Forum Commoner
Posts: 58 Joined: Fri Mar 25, 2005 4:25 pm
Post
by ra » Tue Apr 19, 2005 9:26 am
wow, that's really helpful.
vigge89
Forum Regular
Posts: 875 Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden
Post
by vigge89 » Tue Apr 19, 2005 11:25 am
ra wrote: wow, that's really helpful.
Wait, are you joking or are you serious?
ra
Forum Commoner
Posts: 58 Joined: Fri Mar 25, 2005 4:25 pm
Post
by ra » Sun Apr 24, 2005 12:23 am
joking
ra
Forum Commoner
Posts: 58 Joined: Fri Mar 25, 2005 4:25 pm
Post
by ra » Sun Apr 24, 2005 12:34 am
feyd wrote: you've gotten several straight answers to errors in your code. Count the open and closing parens in Jcart's post.
Next, if you understand some of the fundamentals of regex, you'll see that you have errors in your pattern for what you intended it to be.
And I'm done trying to help on that.
WHen i 'fix' the code according to jcart's suggestion, the script does not work. This is a functional script that i am trying add a word filter to...
And i don't understand any of the fundamentals of regex. that was one of my questions.
ra
Forum Commoner
Posts: 58 Joined: Fri Mar 25, 2005 4:25 pm
Post
by ra » Sun Apr 24, 2005 12:36 am
The added script is:
Code: Select all
$bad_words = array('pthc rompl ranchi pthc pthc ranchi board', 'melissa midwest', 'melissa midwest movies');
$pattern = '%'.preg_quote(implode('|', $bad_words)).'%i';
everyhting else is pre-existing and fully functional.