Jump to content

Archived

This topic is now archived and is closed to further replies.

desithugg

str_replace

Recommended Posts

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.

[code]<?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>";
}
?>[/code]

Share this post


Link to post
Share on other sites
Use an arrray:
[code=php:0]$bad_words = array('shit',
                                  'fuck',
                                  'piss');

$post = str_replace($bad_words, '', $post);[/code]

Share this post


Link to post
Share on other sites
[quote author=wildteen88 link=topic=100900.msg398772#msg398772 date=1153156796]
Use an arrray:
[code=php:0]$bad_words = array('shit',
                                   'fuck',
                                   'piss');

$post = str_replace($bad_words, '', $post);[/code]
[/quote]

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

Share this post


Link to post
Share on other sites
Do you have the code within your while loop like so:
[code=php:0]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[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.