Hi, I have some text loaded from a text field from my database. I am printing it into a javascript array, which has worked in the past (when the text field was a varchar field) but now it fails. The problem is occuring when I print line breaks, as you can see from the javascript error below:

Error: unterminated string literal

Source File:

http://manager.dev/manager/xref/xref_controls_edit.php?type=process&id=12&qid=19
Line: 118, Column: 8

Source Code:

0267] = '1.2. Choose a sample of (insert sample size) firewalls/routers,

The PHP that I am using to print my javsacript array is as follows:

for ($x=0; $x<count($data); $x++) {

if ($data[$x]['element_type']

== 'CTL') {

$cid = $data[$x]['question_id'];

$js_controls .= "arrCTLs[$cid] = '{$data[$x]['tag']} ".trim($data[$x]['title'])."...';"; /******THIS LINE FAILS******/

$js_controls .= "arrCTLpos[$cid] = {$data[$x]['full_order']};";

}

}

The line marked above produces bad javascript, because the $data[$x]['title'] variable contains line breaks which makes the javascript fall over. I have tried all the usual tricks, such as using nl2br and str_replace to remove line breaks (\n), but the javascript source still contains line breaks. I cant get rid of the line breaks, and hence cant get my javascript to work properly.

The $data[$x]['title'] variable makes its way onto the screen in a multiple row list box, if the user ticks the appropriate tick box to put it there. Does anyone have any ideas on how to get rid of my line breaks so that the javascript doesnt fall over?

Here is a snippet of the generated source code as well, so that you can see where the error is occuring:

/********SOURCE*******/

arrSelected[2]=10257;

lookup[10256] = Array('10257','10267','10271','10282','10285'); lookup[10257] = false; lookup[10267] = false; lookup[10271] = false; lookup[10282] = false; lookup[10285] = false; lookup[10287] = Array('10288','10290','10300'); lookup[10288] = false; lookup[10290] = false; lookup[10300] = false; lookup[10304] = Array('10305','10310','10314','10316','10322','10325'); lookup[10305] = false; lookup[10310] = false; lookup[10314] = false; lookup[10316] = false; lookup[10322] = false; lookup[10325] = false; lookup[10336] = Array('10337','10342'); lookup[10337] = false; lookup[10342] = false; lookup[10346] = Array('10347','10349'); lookup[10347] = false; lookup[10349] = false; lookup[10353] = Array('10354','10356','10358','10367','10372'); lookup[10354] = false; lookup[10356] = false; lookup[10358] = false; lookup[10367] = false; lookup[10372] = false; lookup[10383] = Array('10384','10389'); lookup[10384] = false; lookup[10389] = false; lookup[10394] = Array('10395','10397','10400','10402','10405'); lookup[10395] = false; lookup[10397] = false; lookup[10400] = false; lookup[10402] = false; lookup[10405] = false; lookup[10433] = Array('10434','10440','10443','10447','10450','10453','10455','10458','10460','10464'); lookup[10434] = false; lookup[10440] = false; lookup[10443] = false; lookup[10447] = false; lookup[10450] = false; lookup[10453] = false; lookup[10455] = false; lookup[10458] = false; lookup[10460] = false; lookup[10464] = false; lookup[10468] = Array('10469','10471','10479','10486','10488','10494','10497'); lookup[10469] = false; lookup[10471] = false; lookup[10479] = false; lookup[10486] = false; lookup[10488] = false; lookup[10494] = false; lookup[10497] = false; lookup[10500] = Array('10501','10505','10509','10512','10515'); lookup[10501] = false; lookup[10505] = false; lookup[10509] = false; lookup[10512] = false; lookup[10515] = false; lookup[10517] = Array('10518','10523','10525','10536','10538','10545','10548','10551','10557'); lookup[10518] = false; lookup[10523] = false; lookup[10525] = false; lookup[10536] = false; lookup[10538] = false; lookup[10545] = false; lookup[10548] = false; lookup[10551] = false; lookup[10557] = false;

arrCTLs[10257] = '1.1. Obtain and inspect the firewall configuration standards and other documentation specified below to obtain evidence the standards are complete. Also obtain a copy of the following documentation:...';arrCTLpos[10257] = 2;arrCTLs[10267] = '1.2. Choose a sample of (insert sample size) firewalls/routers,

1. between the Internet and the DMZ, and

/********END SOURCE*******/

Lots of points due to tight time scale.

Cheers

Ashley