pillmill
asked on
CR/LF introduced into array read?
Reading from a table into an array and generating a string from the array, I found that
a CR/LF was occasionally introduced into the string. The string is used as a feed to a
graphing program.
How can this be fixed?
a CR/LF was occasionally introduced into the string. The string is used as a feed to a
graphing program.
How can this be fixed?
$array1=array();
$acts=array();
$acts['im'] ="";
$result=mysql_query($str, $link) or die("MySQL Error in reports: ".mysql_error()." ** Query: ".$str);
while($row = mysql_fetch_array($result))
{
$array1[]=$row[1];
$acts['im'] .= $row[1]."," ;
}
$acts['im'] =substr($acts['im'],0,-1);
There is nothing in the code that you have posted that will do that.
You may want to parse the columns that may contain the CR/LF characters and if found, remove them and update the row with the new value.
It should go something like this:
Try it on a test table first to see if you get the results you need.
Also, for the future, look at what's producing the data that goes into the table. If needed, adjust that before it's inserted.
It should go something like this:
UPDATE table_name SET field_name=replace(replace(field_name, CHAR(13), ''), CHAR(10), '');
Try it on a test table first to see if you get the results you need.
Also, for the future, look at what's producing the data that goes into the table. If needed, adjust that before it's inserted.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.