By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,744 Members | 1,716 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,744 IT Pros & Developers. It's quick & easy.

php var with embedded LF to javascript var

P: 4
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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?
$p="string1 \n string2"
?>
<script>
var j="<? echo $p ?>";
alert(j);
</script>
</body>
</html>
Feb 8 '07 #1
Share this Question
Share on Google+
2 Replies


ronverdonk
Expert 2.5K+
P: 4,258
Welcome th The Scripts!

It will work when you code the php variable assignment within single quotes, as follows:
Expand|Select|Wrap|Line Numbers
  1. $p='string1\nstring2';
Ronald :cool:
Feb 8 '07 #2

P: 4
Welcome th The Scripts!

It will work when you code the php variable assignment within single quotes, as follows:
Expand|Select|Wrap|Line Numbers
  1. $p='string1\nstring2';
Ronald :cool:
====================================
Thanks
It worked !
Jose
Feb 8 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.