Netbeans PHP/javascript highlighting

假装没事ソ 提交于 2019-12-05 14:23:08

If you're using only JavaScript + PHP combinations in your file (without HTML), just open the file in which you want to highlight JavaScript syntax, and add this line:

//<script type="text/javascript">

on the top of the page before opening the first PHP tag like this:

//<script type="text/javascript">
<?php
/*The rest of the code..*/
?>

All JavaScript code in this file should be properly highlighted.

In case that you have HTML code somewhere in the middle of the file, you would need to close JavaScript tag before HTML code, and to re-open it again after HTML code like this:

//<script type="text/javascript">
<?php
/*The rest of the code..JavaScript + PHP*/

//</script>
<h1>HTML code</h1><!--HTML code only-->
<p>Bla bla..</p>
//<script type="text/javascript">

/*JavaScript + PHP code again*/

?>

If you don't want these comments to be printed out to your final HTML document, you can create fake PHP function that will never be used by you, only by IDE, on the top of the document like this:

<?php
function higlightJavaScriptCode(){
    ?>
    //<script type="text/javascript">
    <?php
}
/*The rest of the code..*/
?>

@gradosevic Nailed it above, I'll just add my own ultra-compact version that won't output anything to browser:

// Fix Netbeans' jQuery highlighting in mixed PHP/JS. See https://stackoverflow.com/a/21440810/209859
function higlightJavaScriptCode(){?>//<script type="text/javascript"><?php }

I guess the only problem is you can only have one of these per project, or you'd have to start namespacing them.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!