I think the preg_replace is causing the former result to repeat: while($row = mysql_fetch_array($result)){ $old = preg_replace('#&?nbsp;?#i', ' ', $row['content']); $new .= preg_replace("/[^ -þ]/", "", $old); $sql_record2 = "INSERT INTO correction_nbsp (".$acronym."_pages_id, content_before, content_after) VALUES (".$row['id'].", '".$row['content']."', '".$new."')"; mysql_query($sql_record2,$con) or die(mysql_error()); echo $sql_record2."<br />\n"; } PHP: