php var with embedded LF to javascript var

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • medaps
    New Member
    • Feb 2007
    • 4

    #1

    php var with embedded LF to javascript var

    Hi,
    Is there a way to place php var with LF such as: $p="string1 \n string2"
    into: var j="<? echo $p ?>";

    I am getting an error in j assigment: Unterminated string constant
    Thanks


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitl ed Document</title>
    </head>

    <body>
    <?
    $p="string1 \n string2"
    ?>
    <script>
    var j="<? echo $p ?>";
    alert(j);
    </script>
    </body>
    </html>
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Welcome th The Scripts!

    It will work when you code the php variable assignment within single quotes, as follows:
    Code:
    $p='string1\nstring2';
    Ronald :cool:

    Comment

    • medaps
      New Member
      • Feb 2007
      • 4

      #3
      Originally posted by ronverdonk
      Welcome th The Scripts!

      It will work when you code the php variable assignment within single quotes, as follows:
      Code:
      $p='string1\nstring2';
      Ronald :cool:
      =============== =============== ======
      Thanks
      It worked !
      Jose

      Comment

      Working...