Search code examples
phpjavascripthtmltextareacodemirror

Set default language on a CodeMirror TextArea


How can i set that a CodeMirror TextArea will understand PHP WITHOUT echo the tag?

The Textarea

<textarea id="code" name="code">
  <?php
    echo '<?php';
  ?>
</textarea>

The JS script

var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
        lineNumbers: false,
        matchBrackets: true,
        mode: "application/x-httpd-php",
        indentUnit: 4,
        indentWithTabs: true,
        enterMode: "keep",
        tabMode: "shift"
    });

Solution

  • I've solved it, you have to change the mode to mode: "text/x-php",