Jump to content


Photo

swear system


  • Please log in to reply
5 replies to this topic

#1 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 22 June 2006 - 04:58 AM

ok..i am trying to figure out a way to replace swears from my forum into **** what happens is i insert into my database the word and replacement(works fine) and then im trying to use str_replace() to do the rest but its only replacing the last word like that(if there is more then one!, with one it works fine!) I have made a test sentance but i took out the words to post it here and replaced with (swear)

heres the code!

$
lang = array();
$query = "SELECT * FROM words";
$result = mysql_query($query);
while($row = mysql_fetch_row($result)){
$lang[$row[1]] = "$row[2]";
}
foreach($lang as $id => $value){
$par2 = str_replace("$id","$value","What the (swear1) (swear2)");
}
echo "$par2";

Please help!
"Syntax error" .. WHERE THE **** IS IT?!

#2 DieSucker

DieSucker
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 22 June 2006 - 05:01 AM

[!--quoteo(post=386735:date=Jun 21 2006, 11:58 PM:name=legohead6)--][div class=\'quotetop\']QUOTE(legohead6 @ Jun 21 2006, 11:58 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
ok..i am trying to figure out a way to replace swears from my forum into **** what happens is i insert into my database the word and replacement(works fine) and then im trying to use str_replace() to do the rest but its only replacing the last word like that(if there is more then one!, with one it works fine!) I have made a test sentance but i took out the words to post it here and replaced with (swear)

heres the code!

$
lang = array();
$query = "SELECT * FROM words";
$result = mysql_query($query);
while($row = mysql_fetch_row($result)){
$lang[$row[1]] = "$row[2]";
}
foreach($lang as $id => $value){
$par2 = str_replace("$id","$value","What the (swear1) (swear2)");
}
echo "$par2";

Please help!
[/quote]

maybe try preg_replace
[a href=\"http://us2.php.net/manual/en/function.preg-replace.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.preg-replace.php[/a]

#3 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 22 June 2006 - 05:21 AM

[!--quoteo(post=386736:date=Jun 22 2006, 12:01 AM:name=DieSucker)--][div class=\'quotetop\']QUOTE(DieSucker @ Jun 22 2006, 12:01 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
maybe try preg_replace
[a href=\"http://us2.php.net/manual/en/function.preg-replace.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.preg-replace.php[/a]
[/quote]

k heres the code

(line: 10)
$connection = mysql_connect($host,$user,$pass) or die ("Unable to
connect!");
$sent="What the (swear1) (swear2)";
mysql_select_db($db) or die ("Unable to select database!");
$lang = array();
$query = "SELECT * FROM words";
$result = mysql_query($query);
$i=0;
while($row = mysql_fetch_row($result)){
$word[$i] = "$row[1]";
$replace[$i] = "$row[2]";
$i++;
}
$par = preg_replace("$word","$replace","$sent");
echo "$par2";
(line: 25)echo "$sent";

it comes up with

Warning: Delimiter must not be alphanumeric or backslash in /var/www/html/store/swear starer/test.php on line 23
What the (swear1) (swear2)


"Syntax error" .. WHERE THE **** IS IT?!

#4 shortj75

shortj75
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationPort Huron,mi

Posted 22 June 2006 - 06:46 AM

there is a very simple salution here is what i do create a page and name it word .php and heres the code you will need

word.php

<?php
function Smiley($texttoreplace)
{
    $smilies=array( 
    
 //example: "swearword"=>"what you would like to display on your page";   
"fuc*"=>"*$#@", 
"shi@"=>"&%$@",
"as*"=>"*%$", 
//and so on just add the words you want and change fuc* shi@ and as* to the real words
 
    );

    $texttoreplace=str_replace(array_keys($smilies), array_values($smilies), $texttoreplace);
    return $texttoreplace;
}
?>

and on your output page test.php place the folowing

test.php
<?
include 'word.php';
your code here
echo smiley($par2);
?>

i use this script to do the opposite for dirty word on this page [a href=\"http://tfws.dynu.com/joeleinegray/\" target=\"_blank\"]CLICK HERE[/a] when you type in a swear word it say a sentence back to you
The Short One

hopfully this helps if it doesn't sorry
i won't write the code for you!!! you don't learn that way

#5 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 22 June 2006 - 05:13 PM

[!--quoteo(post=386751:date=Jun 22 2006, 01:46 AM:name=shortj75)--][div class=\'quotetop\']QUOTE(shortj75 @ Jun 22 2006, 01:46 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
there is a very simple salution here is what i do create a page and name it word .php and heres the code you will need

word.php

<?php
function Smiley($texttoreplace)
{
    $smilies=array( 
    
 //example: "swearword"=>"what you would like to display on your page";   
"fuc*"=>"*$#@", 
"shi@"=>"&%$@",
"as*"=>"*%$", 
//and so on just add the words you want and change fuc* shi@ and as* to the real words
 
    );

    $texttoreplace=str_replace(array_keys($smilies), array_values($smilies), $texttoreplace);
    return $texttoreplace;
}
?>

and on your output page test.php place the folowing

test.php
<?
include 'word.php';
your code here
echo smiley($par2);
?>

i use this script to do the opposite for dirty word on this page [a href=\"http://tfws.dynu.com/joeleinegray/\" target=\"_blank\"]CLICK HERE[/a] when you type in a swear word it say a sentence back to you
[/quote]

Thanks i your code and merged it with mine and came out with this that works perfectly

$connection = mysql_connect($host,$user,$pass) or die ("Unable to
connect!");
$sent=$_POST['message'];
mysql_select_db($db) or die ("Unable to select database!");
$lang = array();
$query = "SELECT * FROM words";
$result = mysql_query($query);
while($row = mysql_fetch_row($result)){
$lang[$row[1]] = "$row[2]";
}
$par = str_replace(array_keys($lang), array_values($lang),"$sent");
echo "$par<br><br>";
}

echo "<form method=POST>Message:<textarea name=message></textarea><br><input type=submit name=submit value=submit></form>";
?>


heres a page you can try it on ... only b**** a** and f*** work currently i will add more soon!
[a href=\"http://shop.mattswebpage.com/swear%20starer/test.php\" target=\"_blank\"]http://shop.mattswebpage.com/swear%20starer/test.php[/a]
"Syntax error" .. WHERE THE **** IS IT?!

#6 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 22 June 2006 - 05:23 PM

str_replace() accepts arrays in the search and replace parameters:

$search = $replace = array();
$connection = mysql_connect($host,$user,$pass) or die ("Unable to
connect!");
$sent=$_POST['message'];
mysql_select_db($db) or die ("Unable to select database!");
$lang = array();
$query = "SELECT * FROM words";
$result = mysql_query($query);
while($row = mysql_fetch_row($result)){
$search[] = $row[1];
$replace[] = $row[2];
}
$par = str_replace($search, $replace, $sent);
echo "$par<br><br>";
}

echo "<form method=POST>Message:<textarea name=message></textarea><br><input type=submit name=submit value=submit></form>";





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users