str_replace new line

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello;
I have the following  code:

$prps = str_replace("\n", ' ', $input[3]);
$request = str_replace("// var purpose = {} ;\n", "var purpose = '$prps';\n", $request);

In the first line $input[3] is a string formatted with new lines at the end of each line. It is to be used to initialize a javascript variable (in the second line above), in an html file
template.
When the html file is generated from the template, the javascript written to it fails
with unterminated string literal error message.
When opening a view source window, the 'var purpose...' line does have the string broken up with extra spaces at the beginning of each line. This indicates that the new line was not replaced with the space. The space was merely added after
the new line.
How do you replace a new line with php in a case like this?

Testing this is very tedious. Each time I have to go through and undo
file modifications that this function performs in addition to the above.
So it is not just a case of making a change and reloading the file
and rerunning it.

Thanks in advance;
JK

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux