Jump to content


Photo

str_replace


  • Please log in to reply
4 replies to this topic

#1 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 17 July 2006 - 05:17 PM

umm im having trouble using str_replace i want to replace swear words on the $row['post'].I tried setting the row as a global vairable $post = $row['post'] but than it only filters the first post and the rest arent shown.Can someone help me with this.

<?php
$link = mysql_connect('localhost', '1135394704283249', '0309192909121845');
if (!$link) {
   die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('tpf');
if (!$db_selected) {
   die('Could not select database: ' . mysql_error());
}
$query = "SELECT author,post,id FROM post where thread_id = '$thread_id' ORDER BY id ASC limit $start,15";
	 
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){$count++;
echo "<tr><td width='20%' class='nav2' height='130'><a href='http://tpfrpg.byethost32.com/members/index.php?action=view&user1=". $row['author'] ."' class='links'>". $row['author'] ."</a><br><img src='http://tpfrpg.byethost32.com/members/sprite.php?user=". $row['author'] ."'><br><a href='javascript:void(0)' onClick=expandcontent('roster$count')>Roster</a><div id='roster$count' class='switchcontent'><img src='http://tpfrpg.byethost32.com/members/roster.php?user=". $row['author'] ."&slot=1'><img src='http://tpfrpg.byethost32.com/members/roster.php?user=". $row['author'] ."&slot=3'><img src='http://tpfrpg.byethost32.com/members/roster.php?user=". $row['author'] ."&slot=4'><br><img src='http://tpfrpg.byethost32.com/members/roster.php?user=". $row['author'] ."&slot=4'><img src='http://tpfrpg.byethost32.com/members/roster.php?user=". $row['author'] ."&slot=5'><img src='http://tpfrpg.byethost32.com/members/roster.php?user=". $row['author'] ."&slot=6'></div><br><img src='/members/strip.php?user=". $row['author'] ."'></td><td width='60%' class='nav2'>". $row['post'] ."</td><td width='20%' class='nav2'><a href='index.php?action=editpost&post_id=". $row['id'] ."'><img src='http://i63.photobucket.com/albums/h159/saad430/edit.gif' border='0'></a><br><img src='http://i63.photobucket.com/albums/h159/saad430/quote.gif' border='0'><br><a href='index.php?action=deletepost&post_id=". $row['id'] ."'><img src='http://i63.photobucket.com/albums/h159/saad430/delete.gif' border='0'></a><br><img src='http://i63.photobucket.com/albums/h159/saad430/report.gif' border='0'></a></td>";
}
?>


#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 17 July 2006 - 05:19 PM

Use an arrray:
$bad_words = array('shit',
                                   'fuck',
                                   'piss');

$post = str_replace($bad_words, '', $post);


#3 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 17 July 2006 - 05:25 PM

Use an arrray:

$bad_words = array('shit',
                                   'fuck',
                                   'piss');

$post = str_replace($bad_words, '', $post);


i have tried that but when i try assinging
$post to $row['$post'] it doesnt work and when it does work it only displayes  1 post i want it to do the samw with all of them

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 17 July 2006 - 05:27 PM

Do you have the code within your while loop like so:
while($row = mysql_fetch_array($result))
{
    $count++;

    $bad_words = array('shit',
                   'fuck',
                   'piss');
    $row['post'] = str_replace($bad_words, '',  $row['post']);

    // rest of code here


#5 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 17 July 2006 - 05:41 PM

it worked thanks alot




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users