I'm working on someone elses legacy code and they have a weird implementation where they do the following:
- load javascript file into php
- perform a string replace for variables, such as replacing `$intro` with mysql data in the javascript
My problem is that the $intro
data contains carriage returns
so when I perform the string replace
into the javascript with the mysql data it causes the javascript to break.
Here is the line of code in javascript:
dialog.i_intro.value="$intro";
And here is the line of code in php:
$ln=str_replace("\$intro",$intro,$ln);
And here is the data:
dialog.i_intro.value = "Hello World
Hello World
Hello World";
How do I resolve this?
UPDATE I need the carriage returns in the javascript
Im trying the following:
In php:
$intro = str_replace("
","--carriage--",$intro);
In Javascript:
dialog.i_intro.value=dialog.i_intro.value.replace('--carriage--','
');
But something isn't working with this.
EXTENDED UPDATE
I've replaced all line breaks with html breaks. I discovered that the code is interpreting the js using eval
. Here is my current javascript output of the intro variable
.
dialog.i_intro.value="Hi Im Jonathan<br />
<br />
Hi Im Jonathan<br />
<br />
Hi Im Jonathan";
What should I do next?