a tricky tip on indending php&javascript mixed code

What I mean is the autoindent function of some editor that do not understand mixed code language. PHP and Javascript couple is special:

 

<script>
var myJson =
/*<?php if($THIS && $that) { ?>*/
<?php echo json_encode($that); ?>
/*<?php } else { ?>*/
<?php echo json_encode($those); ?>
/*<?php } ?>*/

var isOk = false;
/*<?php if (!$equalthat) { ?>*/
isOk = true;
/*<?php } ?>*/

This is just an example of unclean code I have to understand, but really every editor should understand it as javascript.

The trick is: if you go inside you first close, then open, if you do not go inside, just close the opened comment. For every block. That’s all.

update: too many ‘r’ on title


Posted

in

,

by

Tags: