fork download
  1. <?php
  2.  
  3. $myhtml = '<html>
  4. <body>foo bar
  5. <?php echo "hello world"; ?>
  6. baz
  7. </body>
  8. </html>';
  9.  
  10. function strip_php($text) {
  11. $tokens = token_get_all($text);
  12. foreach($tokens as $index => $token) {
  13. if(!is_array($token) || token_name($token[0]) !== 'T_INLINE_HTML') {
  14. unset($tokens[$index]);
  15. }
  16. else {
  17. echo $token[1];
  18. }
  19. }
  20. }
  21.  
  22. strip_php($myhtml);
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
<html>
<body>foo bar
baz
</body>
</html>