I am having problems removing newlines/carriage returns from textfields submitted by forms:
I am taking user input from a multi-line textfield, and passing it using POST to a MySQL database. Then I access the database entry in another PHP page, where I am converting it into a javaScript variable, Like this:
<script language="javascript">
var message = "<?
mysql_connect (localhost, root, blah);
mysql_select_db (lalanet);
$result2 = mysql_query ("SELECT taker, message, subject FROM news WHERE counter = '$count'");
$row2 = mysql_fetch_array($result2);
print $row2["message"];?>";
</script>
The problem is that the newline characters that the user makes in the multiline textfield screws up the JavaScript, because in javascript variables, Unlike HTML, newline characters newlines aren't ignored or even allowed! I have tried
nl2br($message) but that just inserts "<Br>" where there are newline characters, but doesn't actually remove the newline characters...Fine for HTML output, but not javascript variables...Any ideas?
Thanks