Question

I have PHP which gives minified JS as output through heredoc. Look at this code:

function prerefresh(){$("#len").empty();predata.forEach(item)}

As I have bolded above, the {$ disturbs my heredoc due to variable escaping.

Is there any way to disable or fix such escaping?

Était-ce utile?

La solution

I have PHP which gives minified JS as output through

That's what you are doing wrong.

Don't do any output through heredoc - it makes absolutely no sense in PHP. Just close PHP tag and write whatever JS as is.

?>
function prerefresh(){$("#len").empty();predata.forEach(item)}

it's the most natural way.

Autres conseils

If you are using PHP 5.3 + you could use nowdoc it doesn't parse.

It's in fact variable replacement that you want to disable. And it's escaping what you are looking for:

function prerefresh(){\$("#len").empty();predata.forEach(item)}

use \ backslash to escape the $. Resulting in \$

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top