Ok, so I have a few things here:
Javascript:
desc = "line 1 \n line 2"
jQuery:
$("#msg").text(desc);
PHP:
const NUM = 555;
What I want, is to change the text of the <p>
with the id of msg
, so that it would contain a piece of text with a number of lines, and in one of them the number from the PHP constant.
Like so:
Line 1
Line 2 555, Line 2 continued
Line 3
My problem is how do I mix them all? I tried the following:
var desc = "line 1 \n line2" + <?php echo NUM ?> +"\n line 3";
and that doesn't work.
There are several issues with your code:
define("CONSTANT_NAME", "VALUE");
syntax;\n
has no effect inside HTML tag (if you dont applywhite-space: pre;
orpre-wrap
);<?php echo NUM; ?>
should be wrapped with"
or should be inside JavaScript string;$("#msg").text(desc)
will remove all tags fromdesc
, thus you need to use.html(desc)
instead.What you need is something like this:
PHP
JavaScript