I’ve got a block of PHP generated JavaScript code for WYSIWYG editor which looks like this:
<script>
code contains ', " etc.
</script>
As soon as this script appears on page, specific textarea is replaced by WYSIWYG. But I want to do this only when user asks for it. The problem is, I cannot get this JavaScript into PHP variable, because the editor’s PHP method replace() echos the javascript right away.
So I want to put this <script> into a variable so that I could call it later when user requests it. Is it possible?
One solution came to my mind – put this <script> into external HTML file and load this file via AJAX.
In php one can use output buffering to take any function that outputs text (and even text like this
?> TEXT <?php) and store it in a variable.You’d do something like this:
In order to be able to call this later you could then do something like this:
This is rather hackish and could end you up in a lot of trouble later on especially if the called code changes), so I wouldn’t be the one to recommend it. It may be the easiest way to do this, though.