Example
$string = "Test Line 1
Test Line 2
Test Line 3";
echo str_replace(PHP_EOL,"/".PHP_EOL, $string );
Actually I am expecting output is
Test Line 1 \
Test Line 2 \
Test Line 3 \
Please help me to solve this problem
Example
$string = "Test Line 1
Test Line 2
Test Line 3";
echo str_replace(PHP_EOL,"/".PHP_EOL, $string );
Actually I am expecting output is
Test Line 1 \
Test Line 2 \
Test Line 3 \
Please help me to solve this problem
Use \\
instead of "/"
<?php
$string = "Test Line 1
Test Line 2
Test Line 3";
$var=str_replace(PHP_EOL,"\\"."</br>", $string );
echo $var." \\"; // this append \ in last string
?>
Try this,
Edited:
<?php
$string = "Test Line 1
Test Line 2
Test Line 3";
$str = str_replace(PHP_EOL,"\<br />", $string) . " \\";
echo $str;
?>
If this is just so that you can put the php value into a JS variable, you can just use json_encode()
which will change the new lines to \n
for you
$string = "Test Line 1 Test Line 2 Test Line 3"; echo json_encode($string); // outputs(including quotes) "Test Line 1 \nTest Line 2 \nTest Line 3"