Hey all, I know this has been asked before, and I have tried many of the solutions that were posted in the mailing archives, and also did some googling. But I can't seem to eliminate some new line characters from a string. Here is the scenario:
1. A user inputs some text into an form and submits the form. 2. The information gets put into my MySQL db. 3. I retrieve the information from the db and display it. Now after the user submits the form, I have tried dumping it to the db in a few different ways. First of all, I dumped it directly to the db with no changes, hoping that I could remove the newline characters and other unwanted markup and tags when retrieving the string. I also tried dumping it to the db with after I used some string manipulation function, such as stripslashes, nl2br, htmlentities, stripcslashes, trim, rtrim, and even str_replace. And just to be safe I made sure I double checked to make sure the newlines were removed on before displaying by using some of the same functions, but to no avail. The newlines still seem to be there. In the db, I have tried various different field types, from text to varchar to blob, but this hasn't changed anything either. The reason it is so important that the newline characters be removed is because they are being used to create a javascript string. And if the newline characters are there then, I get an unterminated string error. Here is the current code for adding the user input to the db: <?php function addNewTask($posted) { if(db_conn()) { // building query $notes = trim($posted['notes']); $query = "INSERT INTO tasks (uid,title,due,notes) VALUES ('{$_SESSION['uid']}','{$posted['title']}','"; $query .= (($posted['is_due']==1) ? mktime(23,59,59,$posted['month'],$posted['day'],$posted['year']) : "x"); $query .= "','".$notes."')"; $result = mysql_query($query) or header("Location: http://localhost/errors/script.php?f=addNewTask&r=query_failed"); header("Location: http://localhost/events/task.php?action=add&set=1"); } else { header("Location: http://localhost/errors/script.php?f=addNewTask&r=db_conn"); } } ?> $posted is the array $_POST after it is passed to the function. $_POST['notes'] is where I am having the problem. Here is the code for displaying the information from the db: [library file snippit] <?php function getTasks($uid) { if(db_conn()) { $i=0; $aTask=array(); $query = "SELECT * FROM tasks WHERE uid='{$uid}' AND done<>'1'"; $result = mysql_query($query); while($row=mysql_fetch_assoc($result)) { $aTasks[$i] = array($row['due'],$row['title'],stripslashes($row['notes'])); $i++; } if(isset($aTasks)) { array_multisort($aTasks,SORT_DESC,SORT_STRING); print("<pre>"); print_r($aTasks); print("</pre>"); return($aTasks); } } else { header("Location: http://localhost/errors/script.php?f=getTasks&r=db_conn"); } } ?> [displaying page snippit] <?php $tasks = getTasks($_SESSION['uid']); $len = count($tasks); if($len > 0) { echo("<script language=\"JavaScript\" type=\"text/javascript\">\n"); echo("aTasks = new Array(\n"); $sTask = ""; for($i=0;$i<$len;$i++) { $sTask .= "\""; if($tasks[$i][0] < getNow() && $tasks[$i][0] != "x") $sTask .= "<span class='pastdue'>Past Due!</span><br>"; $sTask .= $tasks[$i][2]."\","; } $sTask = substr($sTask,0,(strlen($sTask) - 1)); echo($sTask.");\n"); echo("</script>\n"); } ?> I know that is going into the db with the newlines still in the string. And I am constantly going back to mysqladmin and the newlines are there, no matter what I do. I was hoping someone could shed some light on what could possibly be causing this. +-------------------------+---------------------+ | Joshua Minnie |Tel: 269.276.9690 | | [EMAIL PROTECTED] |Fax: 269.342.8750 | | www.wildwebtech.com +---------------------+ | | | Independent Web Consultant / Developer | +-----------------------------------------------+ | SYSTEM INFO | +-----------------------------------------------+ | PHP v. 4.2.3 running on Win 2000 / IIS 5 | | MySQL v. 3.23.49 running on RedHat 7.3/Apache | +-----------------------------------------------+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php