I run PHP in JavaScript files, e.g….
var = '<?php /*some code*/ ?>';).
I need to use JavaScript to scan a string for PHP delimiters (the < ? php and ? > that open and close PHP).
I already know the code using JavaScript…
if (b.value.indexOf('<?php')>-1) {alert('PHP delimiter found.');}
What I’m having trouble with is that I need to keep the ability for PHP to be interpretted in JavaScript files (no exceptions). I simply need to output the delimiter strings to the client in JavaScript and not have them interpreted by the server.
So the final output (from the client’s view) would be…
if (b.value.indexOf('<?php')>-1) {alert('PHP delimiter found.');}
With the following code…
if (b.value.indexOf('<?php echo '<?php'; ?>')>-1 || b.value.indexOf('<?php echo '?>'; ?>')>-1)
I get the error: “Parse error: syntax error, unexpected T_LOGICAL_AND”
You could take advantage of Javascript’s ability to parse hex as a character:
In Javascript
'<\x3fphp'is exactly the same thing as'<?php', but it has no meaning in PHP.