aTeam Posted February 15, 2009 Share Posted February 15, 2009 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 Link to comment https://forums.phpfreaks.com/topic/145270-formatting-strings-for-alphabetical-order/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.