JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<textarea id="text" rows="8" cols="50">
<?php
echo Hello();
</textarea>
<br/>
<input type="button" id="btn_run" value="Run"/>
<div id="result">
</div>
JavaScript
$('#btn_run').click(function(){
$('#result').html('');
var lines = $('textarea').val().trim().split('\n');
var rows = lines.length;
if(lines[0].trim() == '<?php'){ //ตรวจสอบบรรทัดแรก เป็นตัวเปิดแท็ก PHP
$('#result').append('<br/>Open tag => OK');
}else{
$('#result').append('<br/>Open tag => FALSE');
}
if(lines[rows-1].trim() == '?>'){ //ตรวจสอบแถวสุดท้าย เป็นตัวปิดแท็ก PHP
$('#result').append('<br/>Close tag => OK');
}else{
$('#result').append('<br/>Close tag => FALSE');
}
});