Jump to content

Formatting strings for alphabetical order


aTeam

Recommended Posts

Hi All,

 

long time reader first time poster.

 

I have implemented a bad word filter to try and remove bad entries from my database output before they are emailed to a customer.

 

The problem is that the bad wordfilter replaces the bad words with spaces which is ok but it leaves the output data full of gaps.

 

So what i need to do is format the output of the string for alphabetical order which will put the data that has been amended to spaces(by the bad wordfilter) to the bottom(right?).

 

here is my code that i have, any assistance with this would be greatly appreciated as i have been searching these forums for quite sometime and have come up with nothing other than a "sort()" function which i believe only works for arrays.

 

 

// execute SQL query and get result  
$sql_result = mysql_query($sql,$connection)  
     or die(mysql_error());   

// Loop through the data set and extract each row in to it's own variable set  
  $names = "";
while ($row = mysql_fetch_array($sql_result)) { 
   
    $names .= $row['value'] . "\n" ;
  
}  

//start word filter
function filter($string) {
$badwords=array("ass","babi","asshole","fark","celaka","pantat","bastard","bitch","penis");
for ($i=0;$i < count($badwords);$i++){      
   $string = str_replace($badwords[$i],str_repeat("",strlen($badwords[$i])),$string);     
}      
return $string; 
} 

//sort filtered output
$filtered_output = filter($names); 

$formatted_output = natsort($filtered_output);

 

-Adam

Archived

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

×
×
  • Create New...

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.