str_replace new line



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
.



Relevant Pages

  • Re: How to link the image files on internet?
    ... not found" html file will be download and saved as JPG. ... How can I know the downloaded file is JPG, but not the "404" html file? ... > Public Function DownloadPicture(ByVal strURL As String) As String ... > Dim xmlhttp As Object ...
    (microsoft.public.access.modulesdaovba)
  • Re: How to replace string in a HTML file ??
    ... > I have an .ASP html file in a server. ... > and I know the name to match in the orginal HTML file. ... > These are string I want to change for playing directly from network ... If you don't know regular expression syntax, take some time to read perlre, ...
    (comp.lang.perl.misc)
  • Re: [PHP] str_replace new line
    ... In the first line $inputis a string formatted with new lines at ... When the html file is generated from the template, ... When opening a view source window, ...
    (php.general)
  • Re: Replace unknow string varible in file.
    ... Imagine a html file full of 100's of these strings all mooshed ... Where the word 'MARKER' is a constant, it stay the same in each string ... unknown length. ... What I need to do it replace each instance of the random letter with a ...
    (comp.lang.python)
  • Re: Compare Two Strings
    ... file in strFileName(it's string) and html file in strFileName(It's ... click the compare button then if that data correct in html file then ... monday.if u understood my prob then plz give me solution with code..if ... and the second string a html file is there.now i want to compare to ...
    (microsoft.public.dotnet.languages.csharp)